Skip to content

Commit 7941125

Browse files
agbishopWitness Patrolclaude
authored
feat: parity batch 17 (BigQuery exact NUMERIC and BIGNUMERIC; Timestream Query static result types and query insights; default-transport test guard) (#2553)
* feat(timestreamquery): static result types, typeof, element-free lambdas, temporal range and spatial coverage insights Queries are parsed and typed before execution, so column types are known for empty results and nested values, typeof reports Timestream type names, and filter and reduce are recognised by their argument's type. Comments are stripped before any rewrite. Query insights report the temporal range and spatial coverage, apply the one query per second limit and are returned only when enabled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * feat(gcpbigquery): exact NUMERIC and BIGNUMERIC arithmetic Decimal values are stored in an order-preserving encoding and computed with exact arithmetic across operators, math functions, casts, aggregates, window functions, formatting, loading, results and extracts. BIGNUMERIC no longer loses digits past scale 9. Parameterised NUMERIC(P,S) types are enforced. Older snapshots convert on restore. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * fix(gcpbigquery): decimals never reach clients encoded; mixed INT64 and NUMERIC joins, IN and IS DISTINCT FROM compare by value Concatenation, LIKE, array-to-string, casts of arrays and structs, FORMAT and error messages could return the internal decimal encoding, and a string that resembled it could be decoded as a decimal. USING joins and IN subqueries between INT64 and NUMERIC columns matched nothing, IS DISTINCT FROM a literal was always true and ARRAY_CONCAT dropped decimal elements. Combining a decimal with a string, bytes, boolean, struct or array is a type error. SEARCH reads decimals inside structs as their decimal text. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * fix(timestreamquery): integer overflow is not rendered wrapped, typeof escapes type names, outer joins keep their scanned range An integer result that overflowed was printed as a wrapped BIGINT, and a 32-bit overflow kept the INTEGER type. A row field name containing a quote broke the typeof rewrite. ON predicates of outer joins narrowed the reported temporal range of the preserved side. Spatial coverage reads the table's partition key through the write service. Rate-limit state is pruned. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * test(azure): private transport for the Functions test client Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * test: no test client runs on the default transport; guard the pattern A test server's Close drops the default transport's idle connections, so a test client without its own transport can have its request broken by another test's teardown. The remaining bare clients use private transports and the test guard now rejects http.Client literals without a Transport. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * test(guards): drop the Cognito exemptions now that those clients have private transports Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * docs: regenerate service READMEs Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY * test(sns): prove non-blocking publish and prompt shutdown by ordering, not elapsed time Both tests compared elapsed time with a 500ms budget, which a loaded runner exceeds without anything blocking. The endpoint now stays blocked until Publish, or Shutdown, has returned. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVwMjLknMM32Xje6Qik6wY --------- Co-authored-by: Witness Patrol <blackbird7181@gmail.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 3171a7d commit 7941125

98 files changed

Lines changed: 13150 additions & 330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ Every service links to its own page with a coverage breakdown — audited operat
748748
| [RDS Data](services/rdsdata/README.md) | A | 7 | 4 structural gaps |
749749
| [Redshift](services/redshift/README.md) | A | 9 | 5 structural gaps |
750750
| [Redshift Data](services/redshiftdata/README.md) | A | 12 | 4 structural gaps; 1 deferred |
751-
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 4 gaps; 1 structural gap |
751+
| [Timestream Query](services/timestreamquery/README.md) | A | 12 | 3 gaps; 1 structural gap |
752752
| [Timestream Write](services/timestreamwrite/README.md) | A | 19 | 1 structural gap |
753753

754754
### Networking & Content Delivery

‎internal/app/cli_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,7 @@ func TestLocalstackCompatibilityEndpoints(t *testing.T) {
31413141

31423142
waitForServerReady(t, port)
31433143

3144-
client := &http.Client{Timeout: 2 * time.Second}
3144+
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
31453145

31463146
tests := []struct {
31473147
validate func(t *testing.T, body map[string]any)

‎internal/app/main_test.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"time"
1717

1818
"github.com/stretchr/testify/require"
19+
20+
"github.com/blackbirdworks/gopherstack/pkgs/httpclient"
1921
)
2022

2123
func TestMultipleServersStartupAndShutdown(t *testing.T) {
@@ -109,7 +111,8 @@ func startServerRetryingPort(t *testing.T, demo bool) (int, chan struct{}, chan
109111
// exits (delivering to errChan), or the deadline elapses. Matching the per-attempt account ID proves
110112
// the responder is this attempt's server, not another test's server that grabbed the port first.
111113
func waitForInstance(port int, accountID string, errChan <-chan error, timeout, interval time.Duration) (bool, error) {
112-
client := &http.Client{Timeout: 1 * time.Second}
114+
client := httpclient.New(1 * time.Second)
115+
defer client.CloseIdleConnections()
113116
deadline := time.Now().Add(timeout)
114117
ticker := time.NewTicker(interval)
115118
defer ticker.Stop()

‎internal/app/timestream_query_sdk_test.go‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,70 @@ func TestTimestreamQuery_SDK_ScheduledQueryWritesTarget(t *testing.T) {
573573
assert.EqualValues(t, 2, desc.ScheduledQuery.LastRunSummary.ExecutionStats.RecordsIngested)
574574
assert.EqualValues(t, 2, desc.ScheduledQuery.LastRunSummary.ExecutionStats.QueryResultRows)
575575
}
576+
577+
func TestTimestreamQuery_SDK_InsightsUsePartitionKey(t *testing.T) {
578+
t.Parallel()
579+
580+
tests := []struct {
581+
key twtypes.PartitionKey
582+
name string
583+
query string
584+
note string
585+
wantKey []string
586+
wantCov float64
587+
}{
588+
{
589+
name: "dimension key",
590+
key: twtypes.PartitionKey{Type: twtypes.PartitionKeyTypeDimension, Name: aws.String("host")},
591+
query: "SELECT * FROM pkdb.m WHERE host = 'h1'",
592+
wantKey: []string{"host"}, wantCov: 0.5, note: "constrained",
593+
},
594+
{
595+
name: "measure key",
596+
key: twtypes.PartitionKey{Type: twtypes.PartitionKeyTypeMeasure},
597+
query: "SELECT * FROM pkdb.m WHERE measure_name = 'cpu'",
598+
wantKey: []string{"measure_name"}, wantCov: 1, note: "all measures are cpu",
599+
},
600+
}
601+
602+
for _, tc := range tests {
603+
t.Run(tc.name, func(t *testing.T) {
604+
t.Parallel()
605+
606+
t0 := time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC)
607+
env := newTimestreamEnv(t, t0)
608+
609+
_, err := env.write.CreateDatabase(
610+
t.Context(),
611+
&twsdk.CreateDatabaseInput{DatabaseName: aws.String("pkdb")},
612+
)
613+
require.NoError(t, err)
614+
615+
_, err = env.write.CreateTable(t.Context(), &twsdk.CreateTableInput{
616+
DatabaseName: aws.String("pkdb"), TableName: aws.String("m"),
617+
Schema: &twtypes.Schema{CompositePartitionKey: []twtypes.PartitionKey{tc.key}},
618+
})
619+
require.NoError(t, err)
620+
621+
_, err = env.write.WriteRecords(t.Context(), &twsdk.WriteRecordsInput{
622+
DatabaseName: aws.String("pkdb"), TableName: aws.String("m"),
623+
Records: []twtypes.Record{
624+
single("cpu", "1", twtypes.MeasureValueTypeDouble, t0.Add(-time.Minute), dim("host", "h1")),
625+
single("cpu", "2", twtypes.MeasureValueTypeDouble, t0.Add(-time.Minute), dim("host", "h2")),
626+
},
627+
})
628+
require.NoError(t, err)
629+
630+
out, err := env.query.Query(t.Context(), &tqsdk.QueryInput{
631+
QueryString: aws.String(tc.query),
632+
QueryInsights: &tqtypes.QueryInsights{Mode: tqtypes.QueryInsightsModeEnabledWithRateControl},
633+
})
634+
require.NoError(t, err)
635+
require.NotNil(t, out.QueryInsightsResponse.QuerySpatialCoverage)
636+
637+
cov := out.QueryInsightsResponse.QuerySpatialCoverage.Max
638+
assert.Equal(t, tc.wantKey, cov.PartitionKey)
639+
assert.InDelta(t, tc.wantCov, cov.Value, 0.001, tc.note)
640+
})
641+
}
642+
}

‎internal/app/timestream_source.go‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ type timestreamRecordSource struct {
2424
}
2525

2626
var (
27-
_ timestreamquerybackend.RecordSource = (*timestreamRecordSource)(nil)
28-
_ timestreamquerybackend.SchemaSource = (*timestreamRecordSource)(nil)
27+
_ timestreamquerybackend.RecordSource = (*timestreamRecordSource)(nil)
28+
_ timestreamquerybackend.SchemaSource = (*timestreamRecordSource)(nil)
29+
_ timestreamquerybackend.PartitionKeySource = (*timestreamRecordSource)(nil)
2930
)
3031

3132
func newTimestreamRecordSource(h *timestreamwritebackend.Handler) *timestreamRecordSource {
@@ -69,6 +70,29 @@ func (s *timestreamRecordSource) TableShapes(region, database, table string) []t
6970
return out
7071
}
7172

73+
// TablePartitionKeys returns the table's customer-defined partition key: dimension names, or measure_name for a
74+
// measure key, in schema order.
75+
func (s *timestreamRecordSource) TablePartitionKeys(region, database, table string) []string {
76+
tbl, err := s.handler.BackendFor(region).DescribeTable(database, table)
77+
if err != nil || tbl.Schema == nil {
78+
return nil
79+
}
80+
81+
keys := make([]string, 0, len(tbl.Schema.CompositePartitionKey))
82+
83+
for _, pk := range tbl.Schema.CompositePartitionKey {
84+
if pk.Type == timestreamwritebackend.PartitionKeyTypeMeasure {
85+
keys = append(keys, "measure_name")
86+
87+
continue
88+
}
89+
90+
keys = append(keys, pk.Name)
91+
}
92+
93+
return keys
94+
}
95+
7296
func (s *timestreamRecordSource) ListDatabases(region string) []string {
7397
dbs := s.handler.BackendFor(region).ListDatabases()
7498
names := make([]string, 0, len(dbs))

‎pkgs/persistence/testdata/snapshot_inventory.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38327,6 +38327,8 @@
3832738327
"QueryInsightsResponse.OutputRows int64 `json:\"OutputRows\"`",
3832838328
"QueryInsightsResponse.QuerySpatialCoverage float64 `json:\"QuerySpatialCoverage,omitempty\"`",
3832938329
"QueryInsightsResponse.QueryTableCount int64 `json:\"QueryTableCount\"`",
38330+
"QueryInsightsResponse.SpatialCoverage *QuerySpatialCoverage `json:\"spatial_coverage,omitempty\"`",
38331+
"QueryInsightsResponse.TemporalRange *QueryTemporalRange `json:\"temporal_range,omitempty\"`",
3833038332
"QueryInsightsResponse.UnloadPartitionCount int64 `json:\"UnloadPartitionCount,omitempty\"`",
3833138333
"QueryInsightsResponse.UnloadWrittenBytes int64 `json:\"UnloadWrittenBytes,omitempty\"`",
3833238334
"QueryInsightsResponse.UnloadWrittenRows int64 `json:\"UnloadWrittenRows,omitempty\"`",
@@ -38336,9 +38338,16 @@
3833638338
"QueryResult.QueryID string",
3833738339
"QueryResult.QueryStatus QueryStatusDetail",
3833838340
"QueryResult.Rows []Row",
38341+
"QuerySpatialCoverage.Max *QuerySpatialCoverageMax `json:\"Max,omitempty\"`",
38342+
"QuerySpatialCoverageMax.PartitionKey []string `json:\"PartitionKey\"`",
38343+
"QuerySpatialCoverageMax.TableArn string `json:\"TableArn\"`",
38344+
"QuerySpatialCoverageMax.Value float64 `json:\"Value\"`",
3833938345
"QueryStatusDetail.CumulativeBytesMetered int64 `json:\"CumulativeBytesMetered\"`",
3834038346
"QueryStatusDetail.CumulativeBytesScanned int64 `json:\"CumulativeBytesScanned\"`",
3834138347
"QueryStatusDetail.ProgressPercentage float64 `json:\"ProgressPercentage\"`",
38348+
"QueryTemporalRange.Max *QueryTemporalRangeMax `json:\"Max,omitempty\"`",
38349+
"QueryTemporalRangeMax.TableArn string `json:\"TableArn\"`",
38350+
"QueryTemporalRangeMax.Value int64 `json:\"Value\"`",
3834238351
"Row.Data []Datum `json:\"Data\"`",
3834338352
"S3ReportLocation.BucketName string `json:\"BucketName,omitempty\"`",
3834438353
"S3ReportLocation.ObjectKey string `json:\"ObjectKey,omitempty\"`",
@@ -38369,7 +38378,9 @@
3836938378
"ScheduledQuery.TargetTable string `json:\"target_table\"`",
3837038379
"ScheduledQueryInsightsResponse.OutputBytes int64 `json:\"OutputBytes\"`",
3837138380
"ScheduledQueryInsightsResponse.OutputRows int64 `json:\"OutputRows\"`",
38381+
"ScheduledQueryInsightsResponse.QuerySpatialCoverage *QuerySpatialCoverage `json:\"QuerySpatialCoverage,omitempty\"`",
3837238382
"ScheduledQueryInsightsResponse.QueryTableCount int64 `json:\"QueryTableCount\"`",
38383+
"ScheduledQueryInsightsResponse.QueryTemporalRange *QueryTemporalRange `json:\"QueryTemporalRange,omitempty\"`",
3837338384
"ScheduledQueryTargetDetail.DimensionMappings []DimensionMapping",
3837438385
"ScheduledQueryTargetDetail.MeasureNameColumn string",
3837538386
"ScheduledQueryTargetDetail.MixedMeasureMappings []MixedMeasureMapping",

‎services/azurefunctions/helpers_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/stretchr/testify/require"
1515

16+
"github.com/blackbirdworks/gopherstack/pkgs/testclient"
1617
"github.com/blackbirdworks/gopherstack/services/azurefunctions"
1718
)
1819

@@ -34,7 +35,7 @@ func newEnv(t *testing.T, withRuntime bool) *env {
3435
azurefunctions.Settings{Domain: testDomain, Port: azurefunctions.DefaultPort, StartupTimeout: 20 * time.Second},
3536
)
3637

37-
e := &env{backend: b, client: &http.Client{Timeout: 30 * time.Second}}
38+
e := &env{backend: b, client: &http.Client{Transport: testclient.New(t).Transport, Timeout: 30 * time.Second}}
3839

3940
if withRuntime {
4041
e.rt = newFakeRuntime()

‎services/cloudformation/resources_extensibility_customresource_lifecycle_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/require"
1212

1313
"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
14+
"github.com/blackbirdworks/gopherstack/pkgs/testclient"
1415
"github.com/blackbirdworks/gopherstack/services/cloudformation"
1516
lambdabackend "github.com/blackbirdworks/gopherstack/services/lambda"
1617
)
@@ -64,7 +65,7 @@ func TestResourceCreator_CustomResource_DeleteEvent(t *testing.T) {
6465
"PhysicalResourceId": ev.PhysicalResourceID,
6566
}
6667
body, _ := json.Marshal(resp, jsonx.V1())
67-
client := &http.Client{Timeout: 2 * time.Second}
68+
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
6869
req, reqErr := http.NewRequestWithContext(
6970
ctx,
7071
http.MethodPut,
@@ -159,7 +160,7 @@ func TestResourceCreator_CustomResource_UpdateEvent(t *testing.T) {
159160
"PhysicalResourceId": ev.PhysicalResourceID,
160161
}
161162
body, _ := json.Marshal(resp, jsonx.V1())
162-
client := &http.Client{Timeout: 2 * time.Second}
163+
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
163164
req, reqErr := http.NewRequestWithContext(
164165
ctx,
165166
http.MethodPut,
@@ -268,7 +269,7 @@ func TestStack_CustomResource_UpdateStack_SendsUpdateEvent(t *testing.T) {
268269
"PhysicalResourceId": physID,
269270
}
270271
body, _ := json.Marshal(resp, jsonx.V1())
271-
client := &http.Client{Timeout: 2 * time.Second}
272+
client := &http.Client{Transport: testclient.New(t).Transport, Timeout: 2 * time.Second}
272273
req, reqErr := http.NewRequestWithContext(
273274
ctx,
274275
http.MethodPut,

‎services/cloudformation/resources_extensibility_customresource_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
1616
"github.com/blackbirdworks/gopherstack/pkgs/page"
17+
"github.com/blackbirdworks/gopherstack/pkgs/testclient"
1718
"github.com/blackbirdworks/gopherstack/services/cloudformation"
1819
lambdabackend "github.com/blackbirdworks/gopherstack/services/lambda"
1920
)
@@ -162,7 +163,7 @@ func TestResourceCreator_CustomResource_ResponseURL_RoundTrip(t *testing.T) {
162163
}
163164

164165
body, _ := json.Marshal(resp, jsonx.V1())
165-
client := &http.Client{}
166+
client := testclient.New(t)
166167
putReq, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url,
167168
newBytesReader(body))
168169
putReq.ContentLength = int64(len(body))
@@ -365,7 +366,7 @@ func TestResourceCreator_CustomResource_FAILEDResponse(t *testing.T) {
365366
"PhysicalResourceId": "failing-resource-001",
366367
}
367368
body, _ := json.Marshal(resp, jsonx.V1())
368-
client := &http.Client{}
369+
client := testclient.New(t)
369370
req, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url, newBytesReader(body))
370371
req.ContentLength = int64(len(body))
371372
res, err := client.Do(req)
@@ -461,7 +462,7 @@ func TestStack_CustomResource_GetAtt_DataOutputs(t *testing.T) {
461462
},
462463
}
463464
body, _ := json.Marshal(resp, jsonx.V1())
464-
client := &http.Client{}
465+
client := testclient.New(t)
465466
req, _ := http.NewRequestWithContext(t.Context(), http.MethodPut, url, newBytesReader(body))
466467
req.ContentLength = int64(len(body))
467468
res, err := client.Do(req)

0 commit comments

Comments
 (0)