Skip to content

Commit bfcb968

Browse files
authored
fix: better int96 support for experimental native scans (#1652)
1 parent e7a3214 commit bfcb968

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

native/core/src/parquet/parquet_exec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fn get_options(session_timezone: &str) -> (TableParquetOptions, SparkParquetOpti
118118
let mut table_parquet_options = TableParquetOptions::new();
119119
table_parquet_options.global.pushdown_filters = true;
120120
table_parquet_options.global.reorder_filters = true;
121+
table_parquet_options.global.coerce_int96 = Some("us".to_string());
121122
let mut spark_parquet_options =
122123
SparkParquetOptions::new(EvalMode::Legacy, session_timezone, false);
123124
spark_parquet_options.allow_cast_unsigned_ints = true;

native/core/src/parquet/parquet_support.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
// under the License.
1717

1818
use crate::execution::operators::ExecutionError;
19-
use arrow::array::{new_null_array, DictionaryArray, StructArray};
20-
use arrow::datatypes::DataType;
2119
use arrow::{
22-
array::{cast::AsArray, types::Int32Type, Array, ArrayRef},
20+
array::{
21+
cast::AsArray, new_null_array, types::Int32Type, types::TimestampMicrosecondType, Array,
22+
ArrayRef, DictionaryArray, StructArray,
23+
},
2324
compute::{cast_with_options, take, CastOptions},
25+
datatypes::{DataType, TimeUnit},
2426
util::display::FormatOptions,
2527
};
2628
use datafusion::common::{Result as DataFusionResult, ScalarValue};
2729
use datafusion::execution::object_store::ObjectStoreUrl;
2830
use datafusion::execution::runtime_env::RuntimeEnv;
2931
use datafusion::physical_plan::ColumnarValue;
30-
use datafusion_comet_spark_expr::utils::array_with_timezone;
3132
use datafusion_comet_spark_expr::EvalMode;
3233
use object_store::path::Path;
3334
use object_store::{parse_url, ObjectStore};
@@ -128,10 +129,6 @@ fn cast_array(
128129
parquet_options: &SparkParquetOptions,
129130
) -> DataFusionResult<ArrayRef> {
130131
use DataType::*;
131-
let array = match to_type {
132-
Timestamp(_, None) => array, // array_with_timezone does not support to_type of NTZ.
133-
_ => array_with_timezone(array, parquet_options.timezone.clone(), Some(to_type))?,
134-
};
135132
let from_type = array.data_type().clone();
136133

137134
let array = match &from_type {
@@ -166,6 +163,14 @@ fn cast_array(
166163
to_type,
167164
parquet_options,
168165
)?),
166+
(Timestamp(TimeUnit::Microsecond, None), Timestamp(TimeUnit::Microsecond, Some(tz))) => {
167+
Ok(Arc::new(
168+
array
169+
.as_primitive::<TimestampMicrosecondType>()
170+
.reinterpret_cast::<TimestampMicrosecondType>()
171+
.with_timezone(Arc::clone(tz)),
172+
))
173+
}
169174
_ => Ok(cast_with_options(&array, to_type, &PARQUET_OPTIONS)?),
170175
}
171176
}

spark/src/test/scala/org/apache/comet/CometCastSuite.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,6 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
900900
}
901901

902902
test("cast TimestampType to LongType") {
903-
// https://github.com/apache/datafusion-comet/issues/1441
904-
assume(!CometConf.isExperimentalNativeScan)
905903
castTest(generateTimestampsExtended(), DataTypes.LongType)
906904
}
907905

@@ -924,14 +922,10 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
924922
}
925923

926924
test("cast TimestampType to StringType") {
927-
// https://github.com/apache/datafusion-comet/issues/1441
928-
assume(!CometConf.isExperimentalNativeScan)
929925
castTest(generateTimestamps(), DataTypes.StringType)
930926
}
931927

932928
test("cast TimestampType to DateType") {
933-
// https://github.com/apache/datafusion-comet/issues/1441
934-
assume(!CometConf.isExperimentalNativeScan)
935929
castTest(generateTimestamps(), DataTypes.DateType)
936930
}
937931

0 commit comments

Comments
 (0)