cockroach_parser_success_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package engine
  2. import (
  3. "context"
  4. "testing"
  5. )
  6. // TestCockroachDBParserSuccess demonstrates the successful integration of CockroachDB's parser
  7. // This test validates that all previously problematic SQL expressions now work correctly
  8. func TestCockroachDBParserSuccess(t *testing.T) {
  9. engine := NewTestSQLEngine()
  10. testCases := []struct {
  11. name string
  12. sql string
  13. expected string
  14. desc string
  15. }{
  16. {
  17. name: "Basic_Function",
  18. sql: "SELECT LENGTH('hello') FROM user_events LIMIT 1",
  19. expected: "5",
  20. desc: "Simple function call",
  21. },
  22. {
  23. name: "Function_Arithmetic",
  24. sql: "SELECT LENGTH('hello') + 10 FROM user_events LIMIT 1",
  25. expected: "15",
  26. desc: "Function with arithmetic operation (original user issue)",
  27. },
  28. {
  29. name: "User_Original_Query",
  30. sql: "SELECT length(trim(' hello world ')) + 12 FROM user_events LIMIT 1",
  31. expected: "23",
  32. desc: "User's exact original failing query - now fixed!",
  33. },
  34. {
  35. name: "String_Concatenation",
  36. sql: "SELECT 'hello' || 'world' FROM user_events LIMIT 1",
  37. expected: "helloworld",
  38. desc: "Basic string concatenation",
  39. },
  40. {
  41. name: "Function_With_Concat",
  42. sql: "SELECT LENGTH('hello' || 'world') FROM user_events LIMIT 1",
  43. expected: "10",
  44. desc: "Function with string concatenation argument",
  45. },
  46. {
  47. name: "Multiple_Arithmetic",
  48. sql: "SELECT LENGTH('test') * 3 FROM user_events LIMIT 1",
  49. expected: "12",
  50. desc: "Function with multiplication",
  51. },
  52. {
  53. name: "Nested_Functions",
  54. sql: "SELECT LENGTH(UPPER('hello')) FROM user_events LIMIT 1",
  55. expected: "5",
  56. desc: "Nested function calls",
  57. },
  58. {
  59. name: "Column_Alias",
  60. sql: "SELECT LENGTH('test') AS test_length FROM user_events LIMIT 1",
  61. expected: "4",
  62. desc: "Column alias functionality (AS keyword)",
  63. },
  64. }
  65. successCount := 0
  66. for _, tc := range testCases {
  67. t.Run(tc.name, func(t *testing.T) {
  68. result, err := engine.ExecuteSQL(context.Background(), tc.sql)
  69. if err != nil {
  70. t.Errorf("❌ %s - Query failed: %v", tc.desc, err)
  71. return
  72. }
  73. if result.Error != nil {
  74. t.Errorf("❌ %s - Query result error: %v", tc.desc, result.Error)
  75. return
  76. }
  77. if len(result.Rows) == 0 {
  78. t.Errorf("❌ %s - Expected at least one row", tc.desc)
  79. return
  80. }
  81. actual := result.Rows[0][0].ToString()
  82. if actual == tc.expected {
  83. t.Logf("SUCCESS: %s → %s", tc.desc, actual)
  84. successCount++
  85. } else {
  86. t.Errorf("FAIL %s - Expected '%s', got '%s'", tc.desc, tc.expected, actual)
  87. }
  88. })
  89. }
  90. t.Logf("CockroachDB Parser Integration: %d/%d tests passed!", successCount, len(testCases))
  91. }