Skip to content

Commit

Permalink
Add JSON extension support for duckdb backends. Closes #467 (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrbasu authored Aug 22, 2024
1 parent 1ee31ba commit 3c647f5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/01-powerpipe-pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
- "check"
- "resource_show_outputs"
- "dashboard"
- "backend"
- "mod"
- "mod_install"
- "sp_files"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/02-powerpipe-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
- "check"
- "resource_show_outputs"
- "dashboard"
- "backend"
- "mod"
- "mod_install"
- "sp_files"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/11-test-acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
- "check"
- "resource_show_outputs"
- "dashboard"
- "backend"
- "mod"
- "mod_install"
- "sp_files"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/viper v1.19.0
github.com/stevenle/topsort v0.2.0 // indirect
github.com/turbot/go-kit v0.10.0-rc.0
github.com/turbot/pipe-fittings v1.5.1
github.com/turbot/pipe-fittings v1.5.4
github.com/turbot/steampipe-plugin-sdk/v5 v5.10.3
github.com/turbot/terraform-components v0.0.0-20231108031935-358f803c1a8b // indirect
github.com/xlab/treeprint v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQ
github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/turbot/go-kit v0.10.0-rc.0 h1:kd+jp2ibbIV33Hc8SsMAN410Dl9Pz6SJ40axbKUlSoA=
github.com/turbot/go-kit v0.10.0-rc.0/go.mod h1:fFQqR59I5z5JeeBLfK1PjSifn4Oprs3NiQx0CxeSJxs=
github.com/turbot/pipe-fittings v1.5.1 h1:ekUvULaoVqpcyEgtpghKEk4q1I5om/nmKyubPdCqcMw=
github.com/turbot/pipe-fittings v1.5.1/go.mod h1:IgGxXEXfG3UTJCIkDOjjErVzU1ClsK6NmxlyaapZaNc=
github.com/turbot/pipe-fittings v1.5.4 h1:I686yzC9F5W3ZCWzdMHVE99VbWKWP0WdjcGh44tIDxA=
github.com/turbot/pipe-fittings v1.5.4/go.mod h1:IgGxXEXfG3UTJCIkDOjjErVzU1ClsK6NmxlyaapZaNc=
github.com/turbot/pipes-sdk-go v0.9.1 h1:2yRojY2wymvJn6NQyE6A0EDFV267MNe+yDLxPVvsBwM=
github.com/turbot/pipes-sdk-go v0.9.1/go.mod h1:Mb+KhvqqEdRbz/6TSZc2QWDrMa5BN3E4Xw+gPt2TRkc=
github.com/turbot/steampipe-plugin-code v0.7.0 h1:SROYIo/TI/Q/YNfXK+sAIS71umypUFm1Uz851TmoJkM=
Expand Down
12 changes: 12 additions & 0 deletions tests/acceptance/test_data/mods/duckdb_mod/query.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
EOQ
}

query "json_casting" {
sql = <<-EOQ
SELECT preferences::JSON FROM employee;
EOQ
}

query "extensions" {
sql = <<-EOQ
select extension_name, installed from duckdb_extensions();
EOQ
}

query "params_only" {
sql = <<-EOQ
SELECT CONCAT($1::text, ' ', $2::text, ' ', $3::text) as "Params" FROM employee;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"CAST(preferences AS ""JSON"")"
"{""theme"": ""dark"", ""notifications"": true}"
"{""theme"": ""light"", ""notifications"": true}"
"{""theme"": ""dark"", ""notifications"": true}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Total Employees
3
22 changes: 22 additions & 0 deletions tests/acceptance/test_files/backend.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"

@test "connecting to a duckdb backend" {
cd $MODS_DIR/duckdb_mod

# run a powerpipe query connecting to a local duckdb database
run powerpipe query run query.total_employee --database duckdb:///$MODS_DIR/duckdb_mod/employee.duckdb --output csv
echo $output
# check output
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_duckdb_backend_total_employee.csv)"
}

@test "using json extension(casting) with duckdb backend" {
cd $MODS_DIR/duckdb_mod

# run a powerpipe query(which performs a JSON casting operation) connecting to a local duckdb database
run powerpipe query run query.json_casting --database duckdb:///$MODS_DIR/duckdb_mod/employee.duckdb --output csv
echo $output
# check output
assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_duckdb_backend_json_casting.csv)"
}

0 comments on commit 3c647f5

Please sign in to comment.