Skip to content

Commit cb24c6d

Browse files
committed
feat: add JSON output format
1 parent 23f8214 commit cb24c6d

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Here is an example of how to do this:
137137
```json
138138
{
139139
"query": "COPY (SELECT * FROM 'https://github.com/Teradata/kylo/raw/refs/heads/master/samples/sample-data/parquet/userdata1.parquet' LIMIT 10) TO '/tmp/output.json'",
140-
"outputFile": "/tmp/output.json"
140+
"outputFile": "/tmp/output.json",
141+
"outputFormat": "json"
141142
}
142143
```

bootstrap.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,26 @@ static invocation_response query_handler(invocation_request const &req, Connecti
7474
// saves the result to a file. If they also specify this filename in the event JSON's `outputFile`
7575
// property, it will be base64 encoded and returned as the result. This temporary file is also deleted before
7676
// the function completes.
77+
7778
auto outputFile = view.GetString("outputFile");
7879
auto encodedOutput = b64encode(outputFile);
7980
// Delete the file after encoding
8081
remove(outputFile.c_str());
8182

82-
return invocation_response::success(encodedOutput,
83-
"application/base64");
83+
if (view.KeyExists("outputFormat"))
84+
{
85+
auto outputFormat = view.GetString("outputFormat");
86+
if (outputFormat == "json")
87+
{
88+
JsonValue jsonResponse;
89+
jsonResponse.WithString("output", encodedOutput);
90+
auto jsonString = jsonResponse.View().WriteCompact();
91+
return invocation_response::success(jsonString, "application/json");
92+
}
93+
}
94+
95+
// Vanilla base64 encoded response
96+
return invocation_response::success(encodedOutput, "application/base64");
8497
}
8598

8699
return invocation_response::success(result->ToString(), "text/plain");

examples/sam/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build-DuckQueryFunction:
2+
echo "This file is intentionally empty. Everything required is provided by the Lambda layer" > $(ARTIFACTS_DIR)/empty
3+

examples/sam/template.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ Globals:
1010
Timeout: 60
1111

1212
Resources:
13-
DuckQueryRuntimeLayer:
14-
Type: AWS::Serverless::Application
15-
Properties:
16-
Location:
17-
ApplicationId: arn:aws:serverlessrepo:eu-west-1:949339270388:applications/duck-query-lambda
18-
SemanticVersion: 0.0.7
13+
# DuckQueryRuntimeLayer:
14+
# Type: AWS::Serverless::Application
15+
# Properties:
16+
# Location:
17+
# ApplicationId: arn:aws:serverlessrepo:eu-west-1:949339270388:applications/duck-query-lambda
18+
# SemanticVersion: 0.0.7
1919

2020
DuckQueryFunction:
2121
Type: AWS::Serverless::Function
2222
Properties:
2323
Runtime: provided.al2023
2424
Handler: bootstrap
2525
Layers:
26-
- !GetAtt DuckQueryRuntimeLayer.Outputs.DuckQueryLayerVersionArn
26+
- "arn:aws:lambda:eu-west-1:935672627075:layer:DuckQueryLambdaLayerArm64:4"
2727
Architectures:
2828
- arm64
2929

template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Resources:
2727
CompatibleArchitectures:
2828
- arm64
2929
CompatibleRuntimes:
30-
- provided
30+
- provided.al2023
3131
LicenseInfo: Apache-2.0
3232
RetentionPolicy: Retain
3333

0 commit comments

Comments
 (0)