Skip to content

Commit

Permalink
Update handling of "serial" type: treat as error, don't generate, and…
Browse files Browse the repository at this point in the history
… produce error when used as param.
  • Loading branch information
shanicky committed Mar 14, 2023
1 parent 2211766 commit ca14bf6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/connector/src/parser/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn do_parse_simd_json_value(dtype: &DataType, v: &BorrowedValue<'_>) -> Result<S
DataType::Int16 => ensure_i16!(v, i16).into(),
DataType::Int32 => ensure_i32!(v, i32).into(),
DataType::Int64 => ensure_i64!(v, i64).into(),
DataType::Serial => ensure_i64!(v, i64).into(),
DataType::Serial => anyhow::bail!("serial should not be parsed"),
// when f32 overflows, the value is converted to `inf` which is inappropriate
DataType::Float32 => {
let scalar_val = ScalarImpl::Float32((simd_json_ensure_float!(v, f32) as f32).into());
Expand Down
2 changes: 1 addition & 1 deletion src/expr/src/vector_op/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ pub fn literal_parsing(
DataType::Int16 => str_parse::<i16>(s)?.into(),
DataType::Int32 => str_parse::<i32>(s)?.into(),
DataType::Int64 => str_parse::<i64>(s)?.into(),
DataType::Serial => str_parse::<i64>(s)?.into(),
DataType::Serial => return Err(None),
DataType::Decimal => str_parse::<Decimal>(s)?.into(),
DataType::Float32 => str_parse::<OrderedF32>(s)?.into(),
DataType::Float64 => str_parse::<OrderedF64>(s)?.into(),
Expand Down
2 changes: 1 addition & 1 deletion src/tests/sqlsmith/src/sql_gen/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn data_type_to_ast_data_type(data_type: &DataType) -> AstDataType {
DataType::Int16 => AstDataType::SmallInt,
DataType::Int32 => AstDataType::Int,
DataType::Int64 => AstDataType::BigInt,
DataType::Serial => AstDataType::Custom(vec!["SERIAL".into()].into()),
DataType::Serial => unreachable!("serial should not be generated"),
DataType::Decimal => AstDataType::Decimal(None, None),
DataType::Float32 => AstDataType::Real,
DataType::Float64 => AstDataType::Double,
Expand Down
7 changes: 3 additions & 4 deletions src/utils/pgwire/src/pg_extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl PreparedStatement {
.to_string(),
Format::Text => cstr_to_str(raw_param).unwrap().to_string(),
},
DataType::Int64 | DataType::Serial => {
DataType::Int64 => {
let tmp = match param_format {
Format::Binary => {
i64::from_sql(&place_hodler, raw_param).unwrap().to_string()
Expand Down Expand Up @@ -521,7 +521,7 @@ impl PreparedStatement {
};
format!("'{}'::JSONB", tmp)
}
DataType::Struct(_) | DataType::List { .. } => {
DataType::Serial | DataType::Struct(_) | DataType::List { .. } => {
return Err(PsqlError::Internal(anyhow!(
"Unsupported param type {:?}",
type_oid
Expand All @@ -542,7 +542,6 @@ impl PreparedStatement {
match oid {
DataType::Boolean => params.push("false".to_string()),
DataType::Int64 => params.push("0::BIGINT".to_string()),
DataType::Serial => params.push("0::BIGINT".to_string()),
DataType::Int16 => params.push("0::SMALLINT".to_string()),
DataType::Int32 => params.push("0::INT".to_string()),
DataType::Float32 => params.push("0::FLOAT4".to_string()),
Expand All @@ -558,7 +557,7 @@ impl PreparedStatement {
}
DataType::Interval => params.push("'2 months ago'::interval".to_string()),
DataType::Jsonb => params.push("'null'::JSONB".to_string()),
DataType::Struct(_) | DataType::List { .. } => {
DataType::Serial | DataType::Struct(_) | DataType::List { .. } => {
return Err(PsqlError::Internal(anyhow!(
"Unsupported param type {:?}",
oid
Expand Down

0 comments on commit ca14bf6

Please sign in to comment.