Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 43fbcb2

Browse files
author
trzysiek
committed
Cleanup 3
1 parent c918b82 commit 43fbcb2

File tree

3 files changed

+42
-72
lines changed

3 files changed

+42
-72
lines changed

platform/parsers/elastic_query_dsl/query_parser.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,6 @@ func (cw *ClickhouseQueryTranslator) parseRange(queryMap QueryMap) model.SimpleQ
808808
// Dates use 1-3 and finish as soon as any succeeds
809809
// Numbers use just 3rd
810810

811-
var funcName string
812811
var finalValue model.Expr
813812
areWeDoneParsing := func() bool {
814813
return finalValue != nil
@@ -820,7 +819,7 @@ func (cw *ClickhouseQueryTranslator) parseRange(queryMap QueryMap) model.SimpleQ
820819
finalValue = dateManager.ParseDateUsualFormat(value, model.NewColumnRef(fieldName)) // stage 1
821820
if !areWeDoneParsing() && (op == "gte" || op == "lte" || op == "gt" || op == "lt") { // stage 2
822821
parsed, err := cw.parseDateMathExpression(value, model.NewColumnRef(fieldName))
823-
fmt.Println("QQQ parsed: ", parsed, funcName, cw.DateMathRenderer)
822+
fmt.Println("QQQ parsed: ", parsed, cw.DateMathRenderer)
824823
if err == nil {
825824
finalValue = parsed
826825
}
@@ -849,9 +848,6 @@ func (cw *ClickhouseQueryTranslator) parseRange(queryMap QueryMap) model.SimpleQ
849848
}
850849
fmt.Println("finalValue1: ", finalValue)
851850

852-
if funcName != "" {
853-
finalValue = model.NewFunction(funcName, finalValue)
854-
}
855851
fmt.Println("finalValue2: ", finalValue)
856852

857853
field := model.NewColumnRef(fieldName)

platform/util/utils.go

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -429,39 +429,7 @@ func AssertSqlEqual(t *testing.T, expected, actual string) {
429429
fmt.Printf("%s\n", SqlPrettyPrint([]byte(actual)))
430430
actualLines := strings.Split(actual, "\n")
431431
expectedLines := strings.Split(expected, "\n")
432-
pp.Println("-- First diff: ")
433-
for i, aLine := range actualLines {
434-
if i >= len(expectedLines) {
435-
fmt.Println("Actual is longer than expected")
436-
break
437-
}
438-
eLine := expectedLines[i]
439-
if aLine != eLine {
440-
if i > 0 {
441-
fmt.Println(" ", actualLines[i-1])
442-
}
443-
fmt.Println(" actual:", aLine)
444-
if i+1 < len(actualLines) {
445-
fmt.Println(" ", actualLines[i+1])
446-
}
447-
fmt.Println()
448-
if i > 0 {
449-
fmt.Println(" ", expectedLines[i-1])
450-
}
451-
fmt.Println("expected:", eLine)
452-
if i+1 < len(expectedLines) {
453-
fmt.Println(" ", expectedLines[i+1])
454-
}
455-
456-
for j := range min(len(aLine), len(eLine)) {
457-
if aLine[j] != eLine[j] {
458-
fmt.Printf("First diff in line %d at index %d (actual: %c, expected: %c)\n", i, j, aLine[j], eLine[j])
459-
break
460-
}
461-
}
462-
break
463-
}
464-
}
432+
pp.Printf("-- First diff: \n%s\n", firstDiff(expectedLines, actualLines))
465433
t.Errorf("Expected: %s\n\nactual: %s", expected, actual)
466434
}
467435
}
@@ -855,39 +823,7 @@ func InitSqlMockWithPrettySqlAndPrint(t *testing.T, matchExpectationsInOrder boo
855823

856824
actualPretty := strings.Split(SqlPrettyPrint([]byte(mismatch.actual)), "\n")
857825
expectedPretty := strings.Split(SqlPrettyPrint([]byte(mismatch.expected)), "\n")
858-
859-
for i, aLine := range actualPretty {
860-
if i >= len(expectedPretty) {
861-
fmt.Println("Actual is longer than expected")
862-
break
863-
}
864-
eLine := expectedPretty[i]
865-
if aLine != eLine {
866-
if i > 0 {
867-
fmt.Println(" ", actualPretty[i-1])
868-
}
869-
fmt.Println(" actual:", aLine)
870-
if i+1 < len(actualPretty) {
871-
fmt.Println(" ", actualPretty[i+1])
872-
}
873-
fmt.Println()
874-
if i > 0 {
875-
fmt.Println(" ", expectedPretty[i-1])
876-
}
877-
fmt.Println("expected:", eLine)
878-
if i+1 < len(expectedPretty) {
879-
fmt.Println(" ", expectedPretty[i+1])
880-
}
881-
882-
for j := range min(len(actualPretty), len(expectedPretty)) {
883-
if actualPretty[j] != expectedPretty[j] {
884-
fmt.Printf("First diff in line %d at index %d (actual: %v, expected: %v)\n", i, j, actualPretty[j], expectedPretty[j])
885-
break
886-
}
887-
}
888-
break
889-
}
890-
}
826+
pp.Printf("-- First diff: \n%s\n", firstDiff(expectedPretty, actualPretty))
891827
}
892828
}
893829
})
@@ -1075,3 +1011,41 @@ func ReadResponseBody(resp *http.Response) ([]byte, error) {
10751011
resp.Body = io.NopCloser(bytes.NewBuffer(respBody))
10761012
return respBody, nil
10771013
}
1014+
1015+
func firstDiff(expectedLines, actualLines []string) string {
1016+
var diff strings.Builder
1017+
for i, aLine := range actualLines {
1018+
if i >= len(expectedLines) {
1019+
fmt.Println("Actual is longer than expected")
1020+
break
1021+
}
1022+
eLine := expectedLines[i]
1023+
if aLine != eLine {
1024+
if i > 0 {
1025+
diff.WriteString(fmt.Sprintf("\t\t%s", actualLines[i-1]))
1026+
}
1027+
diff.WriteString(fmt.Sprintf(" actual: %s", aLine))
1028+
if i+1 < len(actualLines) {
1029+
diff.WriteString(fmt.Sprintf("\t\t%s", actualLines[i+1]))
1030+
}
1031+
diff.WriteString("\n")
1032+
if i > 0 {
1033+
diff.WriteString(fmt.Sprintf("\t\t%s", expectedLines[i-1]))
1034+
}
1035+
diff.WriteString(fmt.Sprintf(" expected: %s", eLine))
1036+
if i+1 < len(expectedLines) {
1037+
diff.WriteString(fmt.Sprintf("\t\t%s", expectedLines[i+1]))
1038+
}
1039+
1040+
for j := range min(len(aLine), len(eLine)) {
1041+
if aLine[j] != eLine[j] {
1042+
diff.WriteString(fmt.Sprintf("First diff in line %d at index %d (actual: %c, expected: %c)\n", i, j, aLine[j], eLine[j]))
1043+
break
1044+
}
1045+
}
1046+
break
1047+
}
1048+
}
1049+
1050+
return diff.String()
1051+
}

smoke-test/async_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ func parseHits(jsonBody map[string]interface{}) []interface{} {
303303
}
304304
// If unable to parse hits, print the JSON body and panic
305305
body, _ := json.MarshalIndent(jsonBody, " ", " ")
306+
fmt.Println("async body", string(body))
306307
panic("Can't parse response: hits: hits")
307308
}
308309

@@ -368,7 +369,6 @@ func validateLog(log logJson) error {
368369
}
369370

370371
func ensureSomeHits(jsonBody map[string]interface{}) bool {
371-
fmt.Println("ensureSomeHits async response", jsonBody)
372372
hits := parseHits(jsonBody)
373373

374374
if len(hits) == 0 {

0 commit comments

Comments
 (0)