Skip to content

Commit cab0f5f

Browse files
consume-improved-response-transform-interface
Summary: - Consume new reponse transform interface. - Support for `json` response transforms. - Support for `text` response transforms.
1 parent d81d930 commit cab0f5f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/spf13/cobra v1.4.0
2020
github.com/spf13/pflag v1.0.5
2121
github.com/spf13/viper v1.10.1
22-
github.com/stackql/any-sdk v0.1.3-alpha13
22+
github.com/stackql/any-sdk v0.1.3-beta01
2323
github.com/stackql/go-suffix-map v0.0.1-alpha01
2424
github.com/stackql/psql-wire v0.1.1-beta23
2525
github.com/stackql/stackql-parser v0.0.14-alpha05

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
484484
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
485485
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
486486
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
487-
github.com/stackql/any-sdk v0.1.3-alpha13 h1:IJLnZojR7JU6f3cixL0U8KdJva+qociPb7Uu3Vctq9w=
488-
github.com/stackql/any-sdk v0.1.3-alpha13/go.mod h1:AKS/g28y7m4SWL/YW8veE9MCNy8XJgaicVibemVE9e8=
487+
github.com/stackql/any-sdk v0.1.3-beta01 h1:97q50CfwKrsU7niQvbASURxshlljoi16uyrnNLyphcI=
488+
github.com/stackql/any-sdk v0.1.3-beta01/go.mod h1:AKS/g28y7m4SWL/YW8veE9MCNy8XJgaicVibemVE9e8=
489489
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
490490
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
491491
github.com/stackql/psql-wire v0.1.1-beta23 h1:1ayYMjZArfDcIMyEOKnm+Bp1zRCISw8pguvTFuUhhVQ=

internal/stackql/execution/mono_valent_execution.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package execution
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"fmt"
76
"io"
@@ -1330,19 +1329,34 @@ func (mv *monoValentExecution) GetExecutor() (func(pc primitive.IPrimitiveCtx) i
13301329
expectedResponse, isExpectedResponse := m.GetResponse()
13311330
if isExpectedResponse {
13321331
responseTransform, responseTransformExists := expectedResponse.GetTransform()
1333-
if responseTransformExists && responseTransform.GetType() == "golang_template_v0.1.0" {
1332+
if responseTransformExists {
13341333
input := stdoutStr
1335-
tmpl := responseTransform.GetBody()
1336-
inStream := stream_transform.NewTextReader(bytes.NewBufferString(input))
1337-
outStream := bytes.NewBuffer(nil)
1338-
tfm, setupErr := stream_transform.NewTemplateStreamTransformer(tmpl, inStream, outStream)
1339-
if setupErr != nil {
1340-
return internaldto.NewErroneousExecutorOutput(fmt.Errorf("template stream transform error: %w", setupErr))
1334+
streamTransformerFactory := stream_transform.NewStreamTransformerFactory(
1335+
responseTransform.GetType(),
1336+
responseTransform.GetBody(),
1337+
)
1338+
if !streamTransformerFactory.IsTransformable() {
1339+
return internaldto.NewErroneousExecutorOutput(
1340+
fmt.Errorf("unsupported template type: %s", responseTransform.GetType()),
1341+
)
13411342
}
1342-
if tfErr := tfm.Transform(); tfErr != nil {
1343-
return internaldto.NewErroneousExecutorOutput(fmt.Errorf("failed to transform: %w", tfErr))
1343+
tfm, getTfmErr := streamTransformerFactory.GetTransformer(input)
1344+
if getTfmErr != nil {
1345+
return internaldto.NewErroneousExecutorOutput(
1346+
fmt.Errorf("failed to transform: %w", getTfmErr))
13441347
}
1345-
outputStr := outStream.String()
1348+
transformError := tfm.Transform()
1349+
if transformError != nil {
1350+
return internaldto.NewErroneousExecutorOutput(
1351+
fmt.Errorf("failed to transform: %w", transformError))
1352+
}
1353+
outStream := tfm.GetOutStream()
1354+
outputBytes, readErr := io.ReadAll(outStream)
1355+
if readErr != nil {
1356+
return internaldto.NewErroneousExecutorOutput(
1357+
fmt.Errorf("failed to read transformed stream: %w", readErr))
1358+
}
1359+
outputStr := string(outputBytes)
13461360
stdoutStr = outputStr
13471361
}
13481362
}

0 commit comments

Comments
 (0)