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

fix: imports for flight-sql features #266

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions sql/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ use std::sync::Arc;
#[cfg(feature = "flight-sql")]
use arrow_schema::{DataType as ArrowDataType, Field as ArrowField, SchemaRef as ArrowSchemaRef};

use databend_client::response::SchemaField as APISchemaField;

use crate::error::{Error, Result};

// Extension types defined by Databend
#[cfg(feature = "flight-sql")]
pub(crate) const EXTENSION_KEY: &str = "Extension";
#[cfg(feature = "flight-sql")]
pub(crate) const ARROW_EXT_TYPE_EMPTY_ARRAY: &str = "EmptyArray";
#[cfg(feature = "flight-sql")]
pub(crate) const ARROW_EXT_TYPE_EMPTY_MAP: &str = "EmptyMap";
#[cfg(feature = "flight-sql")]
pub(crate) const ARROW_EXT_TYPE_VARIANT: &str = "Variant";
#[cfg(feature = "flight-sql")]
pub(crate) const ARROW_EXT_TYPE_BITMAP: &str = "Bitmap";

use databend_client::response::SchemaField as APISchemaField;

use crate::error::{Error, Result};

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NumberDataType {
UInt8,
Expand Down
17 changes: 7 additions & 10 deletions sql/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ use crate::{
error::{ConvertError, Error, Result},
schema::{DecimalDataType, DecimalSize},
};
use itertools::join;
use roaring::RoaringTreemap;
use std::fmt::Write;

use crate::schema::ARROW_EXT_TYPE_BITMAP;
use crate::schema::ARROW_EXT_TYPE_EMPTY_ARRAY;
use crate::schema::ARROW_EXT_TYPE_EMPTY_MAP;
use crate::schema::ARROW_EXT_TYPE_VARIANT;
use crate::schema::EXTENSION_KEY;
use std::fmt::Write;

// Thu 1970-01-01 is R.D. 719163
const DAYS_FROM_CE: i32 = 719_163;
const NULL_VALUE: &str = "NULL";

#[cfg(feature = "flight-sql")]
use {
crate::schema::{
ARROW_EXT_TYPE_BITMAP, ARROW_EXT_TYPE_EMPTY_ARRAY, ARROW_EXT_TYPE_EMPTY_MAP,
ARROW_EXT_TYPE_VARIANT, EXTENSION_KEY,
},
arrow_array::{
Array as ArrowArray, BinaryArray, BooleanArray, Date32Array, Decimal128Array,
Decimal256Array, Float32Array, Float64Array, Int16Array, Int32Array, Int64Array, Int8Array,
Expand Down Expand Up @@ -220,10 +217,10 @@ impl TryFrom<(&ArrowField, &Arc<dyn ArrowArray>, usize)> for Value {
}
return match array.as_any().downcast_ref::<LargeBinaryArray>() {
Some(array) => {
let rb = RoaringTreemap::deserialize_from(array.value(seq))
let rb = roaring::RoaringTreemap::deserialize_from(array.value(seq))
.expect("failed to deserialize bitmap");
let raw = rb.into_iter().collect::<Vec<_>>();
let s = join(raw.iter(), ",");
let s = itertools::join(raw.iter(), ",");
Ok(Value::Bitmap(s))
}
None => Err(ConvertError::new("bitmap", format!("{:?}", array)).into()),
Expand Down