Skip to content

Commit

Permalink
time type
Browse files Browse the repository at this point in the history
  • Loading branch information
rebasedming authored and kysshsy committed Jan 12, 2025
1 parent ecf3fa8 commit 5c2f281
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .history
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#V2
CREATE EXTERNAL TABLE hits\nSTORED AS PARQUET\nLOCATION '/Users/mingying/Documents/hits.parquet';
select count(*) from hits;
SELECT DATE_TRUNC('minute', "EventTime") AS M, COUNT(*) AS PageViews FROM hits WHERE "CounterID" = 62 AND "EventDate" >= '2013-07-14' AND "EventDate" <= '2013-07-15' AND "IsRefresh" = 0 AND "DontCountHits" = 0 GROUP BY DATE_TRUNC('minute', "EventTime") ORDER BY DATE_TRUNC('minute', "EventTime") LIMIT 10 OFFSET 1000;
SELECT DATE_TRUNC('minute', to_timestamp_seconds("EventTime")) AS M, COUNT(*) AS PageViews FROM hits WHERE "CounterID" = 62 AND "EventDate"::INT::DATE >= '2013-07-14' AND "EventDate"::INT::DATE <= '2013-07-15' AND "IsRefresh" = 0 AND "DontCountHits" = 0 GROUP BY DATE_TRUNC('minute', to_timestamp_seconds("EventTime")) ORDER BY DATE_TRUNC('minute', M) LIMIT 10 OFFSET 1000;
select * from hits where "EventDate" >= '2013-07-14' limit 1;
select "EventTime" from hits limit 1;
select to_timestamp_seconds("EventTime") from hits limit 1;
select "EventDate" from hits limit 1;
select '1970-01-01'::date\n;
select '1970-01-01'::date + 15901;
select 15901 / 365;
\\q
select to_timestamp_millis(1238123);
select to_timestamp_millis('2023-01-31T09:26:56.123456789-05:00');
\\q
SELECT AVG("UserID") FROM hits;
CREATE EXTERNAL TABLE hits\nSTORED AS PARQUET\nLOCATION '/Users/mingying/Documents/hits.parquet';
SELECT SUM("AdvEngineID"), COUNT(*), AVG("ResolutionWidth") FROM hits;
SELECT AVG("UserID") FROM hits;
SELECT COUNT(DISTINCT "UserID") FROM hits;
SELECT COUNT(DISTINCT "SearchPhrase") FROM hits;
SELECT MIN("EventDate"), MAX("EventDate") FROM hits;
SELECT "AdvEngineID", COUNT(*) FROM hits WHERE "AdvEngineID" <> 0 GROUP BY "AdvEngineID" ORDER BY COUNT(*) DESC;
SELECT "RegionID", COUNT(DISTINCT "UserID") AS u FROM hits GROUP BY "RegionID" ORDER BY u DESC LIMIT 10;
SELECT "RegionID", SUM("AdvEngineID"), COUNT(*) AS c, AVG("ResolutionWidth"), COUNT(DISTINCT "UserID") FROM hits GROUP BY "RegionID" ORDER BY c DESC LIMIT 10;
SELECT "MobilePhoneModel", COUNT(DISTINCT "UserID") AS u FROM hits WHERE "MobilePhoneModel" <> '' GROUP BY "MobilePhoneModel" ORDER BY u DESC LIMIT 10;
SELECT "UserID", extract(minute FROM to_timestamp("EventTime")) AS m, "SearchPhrase", COUNT(*) FROM hits GROUP BY "UserID", m, "SearchPhrase" ORDER BY COUNT(*) DESC LIMIT 10;
SELECT DATE_TRUNC('minute', to_timestamp("EventTime")) AS M, COUNT(*) AS PageViews FROM hits WHERE "CounterID" = 62 AND to_date("EventDate"::INT) >= '2013-07-14' AND to_date("EventDate"::INT) <= '2013-07-15' AND "IsRefresh" = 0 AND "DontCountHits" = 0 GROUP BY DATE_TRUNC('minute', to_timestamp("EventTime")) ORDER BY DATE_TRUNC('minute', to_timestamp("EventTime")) LIMIT 10 OFFSET 1000;
CREATE EXTERNAL TABLE hits\nSTORED AS PARQUET\nLOCATION '/Users/mingying/Documents/partitioned/hits.parquet';
drop table hits;
CREATE EXTERNAL TABLE hits\nSTORED AS PARQUET\nLOCATION '/Users/mingying/Documents/partitioned/hits.parquet';
CREATE EXTERNAL TABLE hits\nSTORED AS PARQUET\nLOCATION '/Users/mingying/Documents/partitioned/';
select count(*) from hits;
\\q
16 changes: 15 additions & 1 deletion supabase-wrappers/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::instance::ForeignServer;
use crate::FdwRoutine;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::prelude::{Date, Interval, Timestamp, TimestampWithTimeZone};
use pgrx::prelude::{Date, Interval, Time, Timestamp, TimestampWithTimeZone};
use pgrx::{
datum::Uuid,
fcinfo,
Expand Down Expand Up @@ -45,6 +45,7 @@ pub enum Cell {
Numeric(AnyNumeric),
String(String),
Date(Date),
Time(Time),
Timestamp(Timestamp),
Timestamptz(TimestampWithTimeZone),
Interval(Interval),
Expand Down Expand Up @@ -73,6 +74,7 @@ impl Clone for Cell {
Cell::Numeric(v) => Cell::Numeric(v.clone()),
Cell::String(v) => Cell::String(v.clone()),
Cell::Date(v) => Cell::Date(*v),
Cell::Time(v) => Cell::Time(*v),
Cell::Timestamp(v) => Cell::Timestamp(*v),
Cell::Timestamptz(v) => Cell::Timestamptz(*v),
Cell::Interval(v) => Cell::Interval(*v),
Expand Down Expand Up @@ -128,6 +130,13 @@ impl fmt::Display for Cell {
dt_cstr.to_str().expect("date should be a valid string")
)
},
Cell::Time(v) => unsafe {
let tm =
fcinfo::direct_function_call_as_datum(pg_sys::time_out, &[(*v).into_datum()])
.unwrap();
let tm_cstr = CStr::from_ptr(tm.cast_mut_ptr());
write!(f, "'{}'", tm_cstr.to_str().unwrap())
},
Cell::Timestamp(v) => unsafe {
let ts = fcinfo::direct_function_call_as_datum(
pg_sys::timestamp_out,
Expand Down Expand Up @@ -207,6 +216,7 @@ impl IntoDatum for Cell {
Cell::Numeric(v) => v.into_datum(),
Cell::String(v) => v.into_datum(),
Cell::Date(v) => v.into_datum(),
Cell::Time(v) => v.into_datum(),
Cell::Timestamp(v) => v.into_datum(),
Cell::Timestamptz(v) => v.into_datum(),
Cell::Interval(v) => v.into_datum(),
Expand Down Expand Up @@ -239,6 +249,7 @@ impl IntoDatum for Cell {
|| other == pg_sys::NUMERICOID
|| other == pg_sys::TEXTOID
|| other == pg_sys::DATEOID
|| other == pg_sys::TIMEOID
|| other == pg_sys::TIMESTAMPOID
|| other == pg_sys::TIMESTAMPTZOID
|| other == pg_sys::INTERVALOID
Expand Down Expand Up @@ -290,6 +301,9 @@ impl FromDatum for Cell {
PgOid::BuiltIn(PgBuiltInOids::DATEOID) => {
Date::from_datum(datum, is_null).map(Cell::Date)
}
PgOid::BuiltIn(PgBuiltInOids::TIMEOID) => {
Some(Cell::Time(Time::from_datum(datum, is_null).unwrap()))
}
PgOid::BuiltIn(PgBuiltInOids::TIMESTAMPOID) => {
Timestamp::from_datum(datum, is_null).map(Cell::Timestamp)
}
Expand Down
3 changes: 3 additions & 0 deletions supabase-wrappers/src/qual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ pub(crate) unsafe fn form_array_from_datum(
.collect::<Vec<_>>()
})
}
PgOid::BuiltIn(PgBuiltInOids::TIMEARRAYOID) => {
Vec::<Cell>::from_polymorphic_datum(datum, false, pg_sys::TIMEOID)
}
PgOid::BuiltIn(PgBuiltInOids::TIMESTAMPARRAYOID) => {
Array::<Timestamp>::from_polymorphic_datum(datum, is_null, pg_sys::TIMESTAMPOID).map(
|arr| {
Expand Down

0 comments on commit 5c2f281

Please sign in to comment.