diff --git a/source-redshift-batch/.snapshots/TestFeatureFlagUseSchemaInference-Discovery b/source-redshift-batch/.snapshots/TestFeatureFlagUseSchemaInference-Discovery new file mode 100644 index 000000000..6a50a235e --- /dev/null +++ b/source-redshift-batch/.snapshots/TestFeatureFlagUseSchemaInference-Discovery @@ -0,0 +1,60 @@ +Binding 0: +{ + "resource_config_json": { + "name": "test_feature_flag_use_schema_inference_77244729", + "template": "{{if .CursorFields -}}\n {{- if .IsFirstQuery -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\"\n {{- else -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\"\n\t{{- range $i, $k := $.CursorFields -}}\n\t {{- if eq $i 0}} WHERE ({{else}}) OR ({{end -}}\n {{- range $j, $n := $.CursorFields -}}\n\t\t{{- if lt $j $i -}}\n\t\t {{$n}} = ${{add $j 1}} AND {{end -}}\n\t {{- end -}}\n\t {{$k}} \u003e ${{add $i 1}}\n\t{{- end -}}\n\t) \n {{- end}} ORDER BY {{range $i, $k := $.CursorFields}}{{if gt $i 0}}, {{end}}{{$k}}{{end -}};\n{{- else -}}\n SELECT * FROM \"test\".\"feature_flag_use_schema_inference_77244729\";\n{{- end}}\n" + }, + "resource_path": [ + "test_feature_flag_use_schema_inference_77244729" + ], + "collection": { + "name": "acmeCo/test/test_feature_flag_use_schema_inference_77244729", + "read_schema_json": { + "type": "object", + "required": [ + "_meta", + "id" + ], + "properties": { + "_meta": { + "$schema": "http://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/estuary/connectors/source-redshift-batch/document-metadata", + "properties": { + "polled": { + "type": "string", + "format": "date-time", + "title": "Polled Timestamp", + "description": "The time at which the update query which produced this document as executed." + }, + "index": { + "type": "integer", + "title": "Result Index", + "description": "The index of this document within the query execution which produced it." + } + }, + "type": "object", + "required": [ + "polled", + "index" + ] + }, + "data": { + "type": [ + "string", + "null" + ] + }, + "id": { + "type": "integer" + } + }, + "x-infer-schema": true + }, + "key": [ + "/id" + ], + "projections": null + }, + "state_key": "test_feature_flag_use_schema_inference_77244729" + } + diff --git a/source-redshift-batch/main_test.go b/source-redshift-batch/main_test.go index 393f60fd1..1f9b06069 100644 --- a/source-redshift-batch/main_test.go +++ b/source-redshift-batch/main_test.go @@ -328,3 +328,21 @@ func snapshotBindings(t testing.TB, bindings []*pf.CaptureSpec_Binding) { } cupaloy.SnapshotT(t, summary.String()) } + +func TestFeatureFlagUseSchemaInference(t *testing.T) { + var ctx, cs = context.Background(), testCaptureSpec(t) + var control = testControlClient(ctx, t) + var uniqueID = "77244729" + var tableName = fmt.Sprintf("test.feature_flag_use_schema_inference_%s", uniqueID) + + // Includes some extra junk to make sure the parsing helper logic is doing its job as intended + cs.EndpointSpec.(*Config).Advanced.FeatureFlags = "this_flag_does_not_exist,use_schema_inference,,,,no_this_flag_also_does_not_exist" + + executeControlQuery(ctx, t, control, fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)) + t.Cleanup(func() { executeControlQuery(ctx, t, control, fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)) }) + executeControlQuery(ctx, t, control, fmt.Sprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, data TEXT)", tableName)) + + // Discover the table and verify discovery snapshot + cs.Bindings = discoverStreams(ctx, t, cs, regexp.MustCompile(uniqueID)) + t.Run("Discovery", func(t *testing.T) { snapshotBindings(t, cs.Bindings) }) +}