-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Parquet udfs take in
PgRelation
(#209)
* parquet udfs take in pgrelation * tests * upgrade script * checkout origin/dev * 0.3.3 * fix update script name * cargo.lock * drop function in upgrade script * Adapt to 0.3.3 * lock --------- Co-authored-by: Philippe Noël <[email protected]>
- Loading branch information
1 parent
4934ae8
commit 020bf09
Showing
3 changed files
with
201 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
\echo Use "ALTER EXTENSION pg_analytics UPDATE TO '0.3.3'" to load this file. \quit | ||
-- src/api/parquet.rs:52 | ||
-- pg_analytics::api::parquet::parquet_describe | ||
DROP FUNCTION "parquet_describe"(TEXT); | ||
CREATE OR REPLACE FUNCTION "parquet_describe"( | ||
"relation" regclass /* pgrx::rel::PgRelation */ | ||
) RETURNS TABLE ( | ||
"column_name" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"column_type" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"null" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"key" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"default" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"extra" TEXT /* core::option::Option<alloc::string::String> */ | ||
) | ||
STRICT | ||
LANGUAGE c /* Rust */ | ||
AS 'MODULE_PATHNAME', 'parquet_describe_wrapper'; | ||
/* </end connected objects> */ | ||
|
||
-- src/api/parquet.rs:73 | ||
-- pg_analytics::api::parquet::parquet_schema | ||
DROP FUNCTION "parquet_schema"(TEXT); | ||
CREATE OR REPLACE FUNCTION "parquet_schema"( | ||
"relation" regclass /* pgrx::rel::PgRelation */ | ||
) RETURNS TABLE ( | ||
"file_name" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"name" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"type" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"type_length" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"repetition_type" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"num_children" bigint, /* core::option::Option<i64> */ | ||
"converted_type" TEXT, /* core::option::Option<alloc::string::String> */ | ||
"scale" bigint, /* core::option::Option<i64> */ | ||
"precision" bigint, /* core::option::Option<i64> */ | ||
"field_id" bigint, /* core::option::Option<i64> */ | ||
"logical_type" TEXT /* core::option::Option<alloc::string::String> */ | ||
) | ||
STRICT | ||
LANGUAGE c /* Rust */ | ||
AS 'MODULE_PATHNAME', 'parquet_schema_wrapper'; | ||
/* </end connected objects> */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2023-2025 Retake, Inc. | ||
// | ||
// This file is part of ParadeDB - Postgres for Search and Analytics | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
mod fixtures; | ||
|
||
use crate::fixtures::db::Query; | ||
use crate::fixtures::{conn, s3, S3}; | ||
use anyhow::Result; | ||
use rstest::*; | ||
use sqlx::PgConnection; | ||
|
||
use crate::fixtures::tables::nyc_trips::NycTripsTable; | ||
|
||
const S3_TRIPS_BUCKET: &str = "test-trip-setup"; | ||
const S3_TRIPS_KEY: &str = "test_trip_setup.parquet"; | ||
|
||
#[rstest] | ||
async fn test_parquet_describe(#[future(awt)] s3: S3, mut conn: PgConnection) -> Result<()> { | ||
NycTripsTable::setup().execute(&mut conn); | ||
let rows: Vec<NycTripsTable> = "SELECT * FROM nyc_trips".fetch(&mut conn); | ||
s3.client | ||
.create_bucket() | ||
.bucket(S3_TRIPS_BUCKET) | ||
.send() | ||
.await?; | ||
s3.create_bucket(S3_TRIPS_BUCKET).await?; | ||
s3.put_rows(S3_TRIPS_BUCKET, S3_TRIPS_KEY, &rows).await?; | ||
|
||
NycTripsTable::setup_s3_listing_fdw( | ||
&s3.url.clone(), | ||
&format!("s3://{S3_TRIPS_BUCKET}/{S3_TRIPS_KEY}"), | ||
) | ||
.execute(&mut conn); | ||
|
||
let count: (i64,) = "SELECT COUNT(*) FROM parquet_describe('trips')".fetch_one(&mut conn); | ||
assert_eq!(count.0, 15); | ||
Ok(()) | ||
} | ||
|
||
#[rstest] | ||
async fn test_parquet_schema(#[future(awt)] s3: S3, mut conn: PgConnection) -> Result<()> { | ||
NycTripsTable::setup().execute(&mut conn); | ||
let rows: Vec<NycTripsTable> = "SELECT * FROM nyc_trips".fetch(&mut conn); | ||
s3.client | ||
.create_bucket() | ||
.bucket(S3_TRIPS_BUCKET) | ||
.send() | ||
.await?; | ||
s3.create_bucket(S3_TRIPS_BUCKET).await?; | ||
s3.put_rows(S3_TRIPS_BUCKET, S3_TRIPS_KEY, &rows).await?; | ||
|
||
NycTripsTable::setup_s3_listing_fdw( | ||
&s3.url.clone(), | ||
&format!("s3://{S3_TRIPS_BUCKET}/{S3_TRIPS_KEY}"), | ||
) | ||
.execute(&mut conn); | ||
|
||
let count: (i64,) = "SELECT COUNT(*) FROM parquet_schema('trips')".fetch_one(&mut conn); | ||
assert_eq!(count.0, 16); | ||
Ok(()) | ||
} |