feat: data_analysis sql validation & type processing

This commit is contained in:
hjz
2026-04-27 16:05:01 +08:00
committed by lyingbug
parent d812770806
commit 535aec87e3
2 changed files with 90 additions and 7 deletions
+3 -3
View File
@@ -7,7 +7,7 @@ import (
func TestBuildExcelCreateTableSQL_NoSheets(t *testing.T) {
got := buildExcelCreateTableSQL("tbl", "/tmp/data.xlsx", nil)
want := `CREATE TABLE "tbl" AS SELECT * FROM read_xlsx('/tmp/data.xlsx')`
want := `CREATE TABLE "tbl" AS SELECT * FROM read_xlsx('/tmp/data.xlsx', header=true, all_varchar=true)`
if got != want {
t.Fatalf("mismatch.\n got: %s\nwant: %s", got, want)
}
@@ -17,7 +17,7 @@ func TestBuildExcelCreateTableSQL_SingleSheetTagsSource(t *testing.T) {
got := buildExcelCreateTableSQL("tbl", "/tmp/data.xlsx", []string{"Sheet1"})
// Must use read_xlsx (excel extension) with explicit sheet param.
if !strings.Contains(got, "FROM read_xlsx('/tmp/data.xlsx', sheet = 'Sheet1')") {
if !strings.Contains(got, "FROM read_xlsx('/tmp/data.xlsx', sheet = 'Sheet1', header=true, all_varchar=true)") {
t.Fatalf("expected read_xlsx with sheet param, got: %s", got)
}
// Must tag the source sheet name via the synthetic column so downstream
@@ -33,7 +33,7 @@ func TestBuildExcelCreateTableSQL_MultiSheetUsesUnionAllByName(t *testing.T) {
// Each sheet must appear as a SELECT reading that specific sheet, and
// the __sheet_name column must carry its name for per-sheet filtering.
for _, sheet := range []string{"Sheet1", "Sheet2", "报表"} {
needleRead := "FROM read_xlsx('/tmp/data.xlsx', sheet = '" + sheet + "')"
needleRead := "FROM read_xlsx('/tmp/data.xlsx', sheet = '" + sheet + "', header=true, all_varchar=true)"
needleTag := "'" + sheet + "' AS " + excelSheetNameColumn
if !strings.Contains(got, needleRead) {
t.Fatalf("missing read_xlsx for sheet %q in:\n%s", sheet, got)