Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mysql BINARY, VARBINARY and Postgres Type::BYTEA #28

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/sql/arrow_sql_gen/mysql.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::sql::arrow_sql_gen::arrow::map_data_type_to_array_builder_optional;
use arrow::{
array::{
ArrayBuilder, ArrayRef, Date32Builder, Decimal128Builder, Float32Builder, Float64Builder,
Int16Builder, Int32Builder, Int64Builder, Int8Builder, LargeStringBuilder, NullBuilder,
RecordBatch, RecordBatchOptions, Time64NanosecondBuilder, TimestampMillisecondBuilder,
UInt64Builder,
ArrayBuilder, ArrayRef, BinaryBuilder, Date32Builder, Decimal128Builder, Float32Builder,
Float64Builder, Int16Builder, Int32Builder, Int64Builder, Int8Builder, LargeStringBuilder,
NullBuilder, RecordBatch, RecordBatchOptions, Time64NanosecondBuilder,
TimestampMillisecondBuilder, UInt64Builder,
},
datatypes::{DataType, Date32Type, Field, Schema, TimeUnit},
};
Expand Down Expand Up @@ -258,8 +258,6 @@ pub fn rows_to_arrow(rows: &[Row]) -> Result<RecordBatch> {
dec_builder.append_value(val);
}
column_type @ (ColumnType::MYSQL_TYPE_VARCHAR
| ColumnType::MYSQL_TYPE_STRING
| ColumnType::MYSQL_TYPE_VAR_STRING
| ColumnType::MYSQL_TYPE_JSON
| ColumnType::MYSQL_TYPE_TINY_BLOB
| ColumnType::MYSQL_TYPE_BLOB
Expand All @@ -275,6 +273,10 @@ pub fn rows_to_arrow(rows: &[Row]) -> Result<RecordBatch> {
i
);
}
column_type @ (ColumnType::MYSQL_TYPE_STRING
Sevenannn marked this conversation as resolved.
Show resolved Hide resolved
| ColumnType::MYSQL_TYPE_VAR_STRING) => {
handle_primitive_type!(builder, column_type, BinaryBuilder, Vec<u8>, row, i);
}
ColumnType::MYSQL_TYPE_DATE => {
let Some(builder) = builder else {
return NoBuilderForIndexSnafu { index: i }.fail();
Expand Down Expand Up @@ -426,15 +428,15 @@ pub fn map_column_to_data_type(column_type: ColumnType) -> Option<DataType> {
Some(DataType::Time64(TimeUnit::Nanosecond))
}
ColumnType::MYSQL_TYPE_VARCHAR
| ColumnType::MYSQL_TYPE_STRING
| ColumnType::MYSQL_TYPE_VAR_STRING
| ColumnType::MYSQL_TYPE_JSON
| ColumnType::MYSQL_TYPE_ENUM
| ColumnType::MYSQL_TYPE_SET
| ColumnType::MYSQL_TYPE_TINY_BLOB
| ColumnType::MYSQL_TYPE_BLOB
| ColumnType::MYSQL_TYPE_MEDIUM_BLOB
| ColumnType::MYSQL_TYPE_LONG_BLOB => Some(DataType::LargeUtf8),
ColumnType::MYSQL_TYPE_STRING
| ColumnType::MYSQL_TYPE_VAR_STRING => Some(DataType::Binary),

// replication only
ColumnType::MYSQL_TYPE_TYPED_ARRAY
Expand Down
4 changes: 4 additions & 0 deletions src/sql/arrow_sql_gen/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ pub fn rows_to_arrow(rows: &[Row]) -> Result<RecordBatch> {
Type::VARCHAR => {
handle_primitive_type!(builder, Type::VARCHAR, StringBuilder, &str, row, i);
}
Type::BYTEA => {
handle_primitive_type!(builder, Type::BYTEA, BinaryBuilder, Vec<u8>, row, i);
}
Type::BPCHAR => {
let Some(builder) = builder else {
return NoBuilderForIndexSnafu { index: i }.fail();
Expand Down Expand Up @@ -524,6 +527,7 @@ fn map_column_type_to_data_type(column_type: &Type) -> Option<DataType> {
Type::FLOAT4 => Some(DataType::Float32),
Type::FLOAT8 => Some(DataType::Float64),
Type::TEXT | Type::VARCHAR | Type::BPCHAR | Type::UUID => Some(DataType::Utf8),
Type::BYTEA => Some(DataType::Binary),
Type::BOOL => Some(DataType::Boolean),
// Inspect the scale from the first row. Precision will always be 38 for Decimal128.
Type::NUMERIC => None,
Expand Down