TestClassifyOmniParseError pins the dispatcher fallback classifier against the actual omni error strings — empirically derived against omni v0.0.0-20260513072939-39c04c4cca0f. The classifier must label each known Tier-4 grammar gap correctly so the tidb_dispatcher_omni_fallback_total{reason} counter
(t *testing.T)
| 21 | // silently mis-label SEQUENCE rejections as "unknown" and lose the entire |
| 22 | // SEQUENCE telemetry signal. The sql parameter is required, not optional. |
| 23 | func TestClassifyOmniParseError(t *testing.T) { |
| 24 | cases := []struct { |
| 25 | name string |
| 26 | sql string |
| 27 | wantOK bool // expect parse to fail |
| 28 | expected string // counter label |
| 29 | }{ |
| 30 | { |
| 31 | name: "FLASHBACK keyword in error msg AND input", |
| 32 | sql: "FLASHBACK TABLE foo TO BEFORE DROP;", |
| 33 | wantOK: false, |
| 34 | expected: "flashback", |
| 35 | }, |
| 36 | { |
| 37 | name: "SEQUENCE keyword ONLY in input (omni err says 'after CREATE')", |
| 38 | sql: "CREATE SEQUENCE seq;", |
| 39 | wantOK: false, |
| 40 | expected: "sequence", |
| 41 | }, |
| 42 | // NOTE: BATCH non-transactional DML is now SUPPORTED by omni (grammar |
| 43 | // merged in omni #157, consumed via the go.mod bump). It therefore |
| 44 | // parses successfully and no longer reaches the fallback classifier, so |
| 45 | // the previous "omni rejects BATCH" cases were removed. The classifier's |
| 46 | // stale BATCH→batch_dml pattern in metrics.go is dead post-support and is |
| 47 | // tracked for removal as part of the BATCH-support (B1.2) cleanup. |
| 48 | { |
| 49 | name: "genuine syntax error → unknown (no Tier-4 keyword present)", |
| 50 | sql: "SELECT FROM WHERE;", |
| 51 | wantOK: false, |
| 52 | expected: "unknown", |
| 53 | }, |
| 54 | } |
| 55 | |
| 56 | for _, tc := range cases { |
| 57 | t.Run(tc.name, func(t *testing.T) { |
| 58 | _, err := ParseTiDBOmni(tc.sql) |
| 59 | require.Error(t, err, "test setup expects this input to be rejected by current omni") |
| 60 | got := classifyOmniParseError(err, tc.sql) |
| 61 | require.Equal(t, tc.expected, got, |
| 62 | "classifier must return the correct label for omni err %q + sql %q", |
| 63 | err.Error(), tc.sql) |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // TestClassifyOmniParseError_NilErr pins the contract that a nil error |
| 69 | // returns "unknown" — the classifier is called only on the fallback path |
nothing calls this directly
no test coverage detected