Skip to content

Commit

Permalink
Merge commit '8bedecc00b2f1f04d7b1a907152ce0d19b7046a5' into chunchun…
Browse files Browse the repository at this point in the history
…/update-df-may-week-4
  • Loading branch information
appletreeisyellow committed May 28, 2024
2 parents 6eb45b0 + 8bedecc commit 3a229bf
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 222 deletions.
4 changes: 2 additions & 2 deletions datafusion-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

FROM rust:1.73-bullseye as builder
FROM rust:1.78-bookworm as builder

COPY . /usr/src/arrow-datafusion
COPY ./datafusion /usr/src/arrow-datafusion/datafusion
Expand All @@ -28,7 +28,7 @@ RUN rustup component add rustfmt

RUN cargo build --release

FROM debian:bullseye-slim
FROM debian:bookworm-slim

COPY --from=builder /usr/src/arrow-datafusion/datafusion-cli/target/release/datafusion-cli /usr/local/bin

Expand Down
60 changes: 53 additions & 7 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,13 @@ pub(crate) fn from_substrait_type(dt: &substrait::proto::Type) -> Result<DataTyp
),
},
r#type::Kind::List(list) => {
let inner_type =
from_substrait_type(list.r#type.as_ref().ok_or_else(|| {
substrait_datafusion_err!("List type must have inner type")
})?)?;
let field = Arc::new(Field::new_list_field(inner_type, true));
let inner_type = list.r#type.as_ref().ok_or_else(|| {
substrait_datafusion_err!("List type must have inner type")
})?;
let field = Arc::new(Field::new_list_field(
from_substrait_type(inner_type)?,
is_substrait_type_nullable(inner_type)?,
));
match list.type_variation_reference {
DEFAULT_CONTAINER_TYPE_REF => Ok(DataType::List(field)),
LARGE_CONTAINER_TYPE_REF => Ok(DataType::LargeList(field)),
Expand All @@ -1163,8 +1165,11 @@ pub(crate) fn from_substrait_type(dt: &substrait::proto::Type) -> Result<DataTyp
r#type::Kind::Struct(s) => {
let mut fields = vec![];
for (i, f) in s.types.iter().enumerate() {
let field =
Field::new(&format!("c{i}"), from_substrait_type(f)?, true);
let field = Field::new(
&format!("c{i}"),
from_substrait_type(f)?,
is_substrait_type_nullable(f)?,
);
fields.push(field);
}
Ok(DataType::Struct(fields.into()))
Expand All @@ -1175,6 +1180,47 @@ pub(crate) fn from_substrait_type(dt: &substrait::proto::Type) -> Result<DataTyp
}
}

fn is_substrait_type_nullable(dtype: &Type) -> Result<bool> {
fn is_nullable(nullability: i32) -> bool {
nullability != substrait::proto::r#type::Nullability::Required as i32
}

let nullable = match dtype
.kind
.as_ref()
.ok_or_else(|| substrait_datafusion_err!("Type must contain Kind"))?
{
r#type::Kind::Bool(val) => is_nullable(val.nullability),
r#type::Kind::I8(val) => is_nullable(val.nullability),
r#type::Kind::I16(val) => is_nullable(val.nullability),
r#type::Kind::I32(val) => is_nullable(val.nullability),
r#type::Kind::I64(val) => is_nullable(val.nullability),
r#type::Kind::Fp32(val) => is_nullable(val.nullability),
r#type::Kind::Fp64(val) => is_nullable(val.nullability),
r#type::Kind::String(val) => is_nullable(val.nullability),
r#type::Kind::Binary(val) => is_nullable(val.nullability),
r#type::Kind::Timestamp(val) => is_nullable(val.nullability),
r#type::Kind::Date(val) => is_nullable(val.nullability),
r#type::Kind::Time(val) => is_nullable(val.nullability),
r#type::Kind::IntervalYear(val) => is_nullable(val.nullability),
r#type::Kind::IntervalDay(val) => is_nullable(val.nullability),
r#type::Kind::TimestampTz(val) => is_nullable(val.nullability),
r#type::Kind::Uuid(val) => is_nullable(val.nullability),
r#type::Kind::FixedChar(val) => is_nullable(val.nullability),
r#type::Kind::Varchar(val) => is_nullable(val.nullability),
r#type::Kind::FixedBinary(val) => is_nullable(val.nullability),
r#type::Kind::Decimal(val) => is_nullable(val.nullability),
r#type::Kind::PrecisionTimestamp(val) => is_nullable(val.nullability),
r#type::Kind::PrecisionTimestampTz(val) => is_nullable(val.nullability),
r#type::Kind::Struct(val) => is_nullable(val.nullability),
r#type::Kind::List(val) => is_nullable(val.nullability),
r#type::Kind::Map(val) => is_nullable(val.nullability),
r#type::Kind::UserDefined(val) => is_nullable(val.nullability),
r#type::Kind::UserDefinedTypeReference(_) => true, // not implemented, assume nullable
};
Ok(nullable)
}

fn from_substrait_bound(
bound: &Option<Bound>,
is_lower: bool,
Expand Down
Loading

0 comments on commit 3a229bf

Please sign in to comment.