forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sqllogictest] Support
pg_typeof
(apache#5148)
* [sqllogictest] Support `pg_typeof` * add newline * Add a license header
- Loading branch information
Showing
4 changed files
with
227 additions
and
0 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
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 |
---|---|---|
|
@@ -30,6 +30,9 @@ use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; | |
use postgres_types::Type; | ||
use rust_decimal::Decimal; | ||
use tokio_postgres::{Column, Row}; | ||
use types::PgRegtype; | ||
|
||
mod types; | ||
|
||
// default connect string, can be overridden by the `PG_URL` environment variable | ||
const PG_URI: &str = "postgresql:https://[email protected]/test"; | ||
|
@@ -245,6 +248,7 @@ fn cell_to_string(row: &Row, column: &Column, idx: usize) -> String { | |
} | ||
Type::FLOAT4 => make_string!(row, idx, f32, f32_to_str), | ||
Type::FLOAT8 => make_string!(row, idx, f64, f64_to_str), | ||
Type::REGTYPE => make_string!(row, idx, PgRegtype), | ||
_ => unimplemented!("Unsupported type: {}", column.type_().name()), | ||
} | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
datafusion/core/tests/sqllogictests/src/engines/postgres/types.rs
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,44 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http:https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use postgres_types::Type; | ||
use tokio_postgres::types::FromSql; | ||
|
||
pub struct PgRegtype { | ||
value: String, | ||
} | ||
|
||
impl<'a> FromSql<'a> for PgRegtype { | ||
fn from_sql( | ||
_: &Type, | ||
buf: &'a [u8], | ||
) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> { | ||
let oid = postgres_protocol::types::oid_from_sql(buf)?; | ||
let value = Type::from_oid(oid).ok_or("bad type")?.to_string(); | ||
Ok(PgRegtype { value }) | ||
} | ||
|
||
fn accepts(ty: &Type) -> bool { | ||
matches!(*ty, Type::REGTYPE) | ||
} | ||
} | ||
|
||
impl ToString for PgRegtype { | ||
fn to_string(&self) -> String { | ||
self.value.clone() | ||
} | ||
} |
178 changes: 178 additions & 0 deletions
178
datafusion/core/tests/sqllogictests/test_files/pg_compat/pg_compat_type_coercion.slt
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,178 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
|
||
# http:https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
query ?? | ||
select true and true, false and false; | ||
---- | ||
true false | ||
|
||
|
||
onlyif DataFusion | ||
query ?? | ||
select arrow_typeof(true and true), arrow_typeof(false and false); | ||
---- | ||
Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ?? | ||
select pg_typeof(true and true), pg_typeof(false and false); | ||
---- | ||
bool bool | ||
|
||
|
||
query ?? | ||
select true or true, false or false; | ||
---- | ||
true false | ||
|
||
|
||
onlyif DataFusion | ||
query ?? | ||
select arrow_typeof(true or true), arrow_typeof(false or false); | ||
---- | ||
Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ?? | ||
select pg_typeof(true or true), pg_typeof(false or false); | ||
---- | ||
bool bool | ||
|
||
|
||
query ?? | ||
select false and true, true and false; | ||
---- | ||
false false | ||
|
||
|
||
onlyif DataFusion | ||
query ?? | ||
select arrow_typeof(false and true), arrow_typeof(true and false); | ||
---- | ||
Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ?? | ||
select pg_typeof(false and true), pg_typeof(true and false); | ||
---- | ||
bool bool | ||
|
||
|
||
query ?? | ||
select false or true, true or false; | ||
---- | ||
true true | ||
|
||
|
||
onlyif DataFusion | ||
query ?? | ||
select arrow_typeof(false or true), arrow_typeof(true or false); | ||
---- | ||
Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ?? | ||
select pg_typeof(false or true), pg_typeof(true or false); | ||
---- | ||
bool bool | ||
|
||
|
||
# TODO: run for DataFusion as well after #4335 | ||
onlyif postgres | ||
query ?? | ||
select null and null, null or null; | ||
---- | ||
NULL NULL | ||
|
||
|
||
# TODO: uncomment after #4335 | ||
#onlyif DataFusion | ||
#query ?? | ||
#select arrow_typeof(null and null), arrow_typeof(null or null); | ||
#---- | ||
#Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ?? | ||
select pg_typeof(null and null), pg_typeof(null or null); | ||
---- | ||
bool bool | ||
|
||
|
||
onlyif postgres | ||
query ???? | ||
select true and null, | ||
false and null, | ||
null and true, | ||
null and false; | ||
---- | ||
NULL false NULL false | ||
|
||
|
||
onlyif DataFusion | ||
query ???? | ||
select arrow_typeof(true and null), | ||
arrow_typeof(false and null), | ||
arrow_typeof(null and true), | ||
arrow_typeof(null and false); | ||
---- | ||
Boolean Boolean Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ???? | ||
select pg_typeof(true and null), | ||
pg_typeof(false and null), | ||
pg_typeof(null and true), | ||
pg_typeof(null and false); | ||
---- | ||
bool bool bool bool | ||
|
||
|
||
onlyif postgres | ||
query ???? | ||
select true or null, | ||
false or null, | ||
null or true, | ||
null or false; | ||
---- | ||
true NULL true NULL | ||
|
||
|
||
onlyif DataFusion | ||
query ???? | ||
select arrow_typeof(true or null), | ||
arrow_typeof(false or null), | ||
arrow_typeof(null or true), | ||
arrow_typeof(null or false); | ||
---- | ||
Boolean Boolean Boolean Boolean | ||
|
||
|
||
onlyif postgres | ||
query ???? | ||
select pg_typeof(true or null), | ||
pg_typeof(false or null), | ||
pg_typeof(null or true), | ||
pg_typeof(null or false); | ||
---- | ||
bool bool bool bool |