Skip to content

Commit 60ce77b

Browse files
committed
fix(query): support compiler warning message codes
1 parent 85194da commit 60ce77b

File tree

10 files changed

+155
-120
lines changed

10 files changed

+155
-120
lines changed

adapters/apex/apex_test.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package apex
22

33
import (
44
"bufio"
5-
"encoding/json"
65
"fmt"
76
"io"
87
"net/http"
@@ -56,7 +55,7 @@ func TestHandler(t *testing.T) {
5655
b, err := io.ReadAll(zsr)
5756
assert.NoError(t, err)
5857

59-
JSONEqExp(t, exp, string(b), []string{ingest.TimestampField})
58+
testhelper.JSONEqExp(t, exp, string(b), []string{ingest.TimestampField})
6059

6160
atomic.AddUint64(&hasRun, 1)
6261

@@ -130,31 +129,3 @@ func setup(t *testing.T) func(dataset string, client *axiom.Client) *log.Logger
130129
return logger
131130
}
132131
}
133-
134-
// JSONEqExp is like assert.JSONEq() but excludes the given fields.
135-
func JSONEqExp(t assert.TestingT, expected string, actual string, excludedFields []string, msgAndArgs ...any) bool {
136-
type tHelper interface {
137-
Helper()
138-
}
139-
140-
if h, ok := t.(tHelper); ok {
141-
h.Helper()
142-
}
143-
144-
var expectedJSONAsInterface, actualJSONAsInterface map[string]any
145-
146-
if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil {
147-
return assert.Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
148-
}
149-
150-
if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
151-
return assert.Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
152-
}
153-
154-
for _, excludedField := range excludedFields {
155-
delete(expectedJSONAsInterface, excludedField)
156-
delete(actualJSONAsInterface, excludedField)
157-
}
158-
159-
return assert.Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...)
160-
}

axiom/query/result.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package query
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67
"time"
78
)
89

@@ -19,9 +20,17 @@ const (
1920
MissingColumn // missing_column
2021
LicenseLimitForQueryWarning // license_limit_for_query_warning
2122
DefaultLimitWarning // default_limit_warning
23+
24+
// CompilerWarning is a generic code. Please inspect the message text for
25+
// more details.
26+
CompilerWarning // apl_
2227
)
2328

2429
func messageCodeFromString(s string) (mc MessageCode, err error) {
30+
if strings.HasPrefix(s, CompilerWarning.String()) {
31+
return CompilerWarning, nil
32+
}
33+
2534
switch s {
2635
case emptyMessageCode.String():
2736
mc = emptyMessageCode

axiom/query/result_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axiom/query/result_test.go

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/axiomhq/axiom-go/internal/test/testhelper"
1212
)
1313

14-
func TestStatus(t *testing.T) {
15-
exp := Status{
14+
var (
15+
expStatus = Status{
1616
ElapsedTime: time.Second,
1717
BlocksExamined: 10,
1818
RowsExamined: 100000,
@@ -21,33 +21,27 @@ func TestStatus(t *testing.T) {
2121
IsPartial: true,
2222
ContinuationToken: "123",
2323
IsEstimate: true,
24-
MaxBlockTime: time.Now().UTC(),
25-
MinBlockTime: time.Now().UTC().Add(-time.Hour),
24+
MinBlockTime: parseTimeOrPanic("2022-08-15T10:55:53Z"),
25+
MaxBlockTime: parseTimeOrPanic("2022-08-15T11:55:53Z"),
2626
Messages: []Message{
2727
{
2828
Priority: Error,
2929
Code: MissingColumn,
3030
Count: 2,
3131
Text: "missing column",
3232
},
33+
{
34+
Priority: Warn,
35+
Code: CompilerWarning,
36+
Count: 1,
37+
Text: "some apl compiler warning",
38+
},
3339
},
3440
MinCursor: "c776x1uafkpu-4918f6cb9000095-0",
3541
MaxCursor: "c776x1uafnvq-4918f6cb9000095-1",
3642
}
3743

38-
b, err := json.Marshal(exp)
39-
require.NoError(t, err)
40-
require.NotEmpty(t, b)
41-
42-
var act Status
43-
err = json.Unmarshal(b, &act)
44-
require.NoError(t, err)
45-
46-
assert.Equal(t, exp, act)
47-
}
48-
49-
func TestStatus_MarshalJSON(t *testing.T) {
50-
exp := `{
44+
expStatusJSON = `{
5145
"elapsedTime": 1000000,
5246
"blocksExamined": 10,
5347
"rowsExamined": 100000,
@@ -64,38 +58,37 @@ func TestStatus_MarshalJSON(t *testing.T) {
6458
"code": "missing_column",
6559
"count": 2,
6660
"msg": "missing column"
61+
},
62+
{
63+
"priority": "warn",
64+
"code": "apl_convertingfromtypestotypes_1",
65+
"count": 1,
66+
"msg": "some apl compiler warning"
6767
}
6868
],
6969
"minCursor": "c776x1uafkpu-4918f6cb9000095-0",
7070
"maxCursor": "c776x1uafnvq-4918f6cb9000095-1"
7171
}`
72+
)
7273

73-
act, err := Status{
74-
ElapsedTime: time.Second,
75-
BlocksExamined: 10,
76-
RowsExamined: 100000,
77-
RowsMatched: 2,
78-
NumGroups: 1,
79-
IsPartial: true,
80-
ContinuationToken: "123",
81-
IsEstimate: true,
82-
MinBlockTime: testhelper.MustTimeParse(t, time.RFC3339, "2022-08-15T10:55:53Z"),
83-
MaxBlockTime: testhelper.MustTimeParse(t, time.RFC3339, "2022-08-15T11:55:53Z"),
84-
Messages: []Message{
85-
{
86-
Priority: Error,
87-
Code: MissingColumn,
88-
Count: 2,
89-
Text: "missing column",
90-
},
91-
},
92-
MinCursor: "c776x1uafkpu-4918f6cb9000095-0",
93-
MaxCursor: "c776x1uafnvq-4918f6cb9000095-1",
94-
}.MarshalJSON()
74+
func TestStatus(t *testing.T) {
75+
b, err := json.Marshal(expStatus)
76+
require.NoError(t, err)
77+
require.NotEmpty(t, b)
78+
79+
var act Status
80+
err = json.Unmarshal(b, &act)
81+
require.NoError(t, err)
82+
83+
assert.Equal(t, expStatus, act)
84+
}
85+
86+
func TestStatus_MarshalJSON(t *testing.T) {
87+
act, err := expStatus.MarshalJSON()
9588
require.NoError(t, err)
9689
require.NotEmpty(t, act)
9790

98-
assert.JSONEq(t, exp, string(act))
91+
testhelper.JSONEqExp(t, expStatusJSON, string(act), []string{"messages.1.code"})
9992
}
10093

10194
func TestStatus_UnmarshalJSON(t *testing.T) {
@@ -125,17 +118,17 @@ func TestMessageCode_String(t *testing.T) {
125118
assert.Empty(t, MessageCode(0).String())
126119
assert.Empty(t, emptyMessageCode.String())
127120
assert.Equal(t, emptyMessageCode, MessageCode(0))
128-
assert.Contains(t, (DefaultLimitWarning + 1).String(), "MessageCode(")
121+
assert.Contains(t, (CompilerWarning + 1).String(), "MessageCode(")
129122

130-
for mc := VirtualFieldFinalizeError; mc <= DefaultLimitWarning; mc++ {
123+
for mc := VirtualFieldFinalizeError; mc <= CompilerWarning; mc++ {
131124
s := mc.String()
132125
assert.NotEmpty(t, s)
133126
assert.NotContains(t, s, "MessageCode(")
134127
}
135128
}
136129

137130
func TestMessageCodeFromString(t *testing.T) {
138-
for mc := VirtualFieldFinalizeError; mc <= DefaultLimitWarning; mc++ {
131+
for mc := VirtualFieldFinalizeError; mc <= CompilerWarning; mc++ {
139132
s := mc.String()
140133

141134
parsedMC, err := messageCodeFromString(s)
@@ -181,3 +174,11 @@ func TestMessagePriorityFromString(t *testing.T) {
181174
assert.Equal(t, mp, parsedMP)
182175
}
183176
}
177+
178+
func parseTimeOrPanic(value string) time.Time {
179+
t, err := time.Parse(time.RFC3339, value)
180+
if err != nil {
181+
panic(err)
182+
}
183+
return t
184+
}

axiom/querylegacy/result.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package querylegacy
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67
"time"
78
)
89

@@ -19,9 +20,17 @@ const (
1920
MissingColumn // missing_column
2021
LicenseLimitForQueryWarning // license_limit_for_query_warning
2122
DefaultLimitWarning // default_limit_warning
23+
24+
// CompilerWarning is a generic code. Please inspect the message text for
25+
// more details.
26+
CompilerWarning // apl_
2227
)
2328

2429
func messageCodeFromString(s string) (mc MessageCode, err error) {
30+
if strings.HasPrefix(s, CompilerWarning.String()) {
31+
return CompilerWarning, nil
32+
}
33+
2534
switch s {
2635
case emptyMessageCode.String():
2736
mc = emptyMessageCode

axiom/querylegacy/result_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)