gene-bordegaray commented on code in PR #22607:
URL: https://github.com/apache/datafusion/pull/22607#discussion_r3323731070
##########
datafusion/sqllogictest/src/test_context.rs:
##########
@@ -286,6 +303,212 @@ fn register_strict_schema_provider(ctx: &SessionContext) {
);
}
+//
==============================================================================
+// Range Partitioned Table (sqllogictest-only)
+//
==============================================================================
+
+#[derive(Debug)]
+struct RangePartitionedTable {
+ schema: SchemaRef,
+ partitions: Vec<Vec<RecordBatch>>,
+ range_column_index: usize,
+ split_points: Vec<SplitPoint>,
+}
+
+#[async_trait]
+impl TableProvider for RangePartitionedTable {
+ fn schema(&self) -> SchemaRef {
+ Arc::clone(&self.schema)
+ }
+
+ fn table_type(&self) -> TableType {
+ TableType::Base
+ }
+
+ async fn scan(
+ &self,
+ state: &dyn Session,
+ projection: Option<&Vec<usize>>,
+ _filters: &[Expr],
+ _limit: Option<usize>,
+ ) -> Result<Arc<dyn ExecutionPlan>> {
+ let projected_schema = project_schema(&self.schema, projection)?;
+ let mut source = MemorySourceConfig::try_new(
+ &self.partitions,
+ Arc::clone(&self.schema),
+ projection.cloned(),
+ )?;
+ source =
source.with_show_sizes(state.config_options().explain.show_sizes);
+
+ let output_partitioning =
+ self.output_partitioning(projection, &projected_schema)?;
+ let source = RangePartitionedSource {
+ inner: source,
+ output_partitioning,
+ };
+
+ Ok(DataSourceExec::from_data_source(source))
+ }
+}
+
+impl RangePartitionedTable {
+ fn output_partitioning(
+ &self,
+ projection: Option<&Vec<usize>>,
+ projected_schema: &SchemaRef,
+ ) -> Result<Partitioning> {
+ let Some(projected_range_index) =
+ projected_index(self.range_column_index, projection)
+ else {
+ return
Ok(Partitioning::UnknownPartitioning(self.partitions.len()));
+ };
+
+ let range_column =
projected_schema.field(projected_range_index).name();
+ let ordering = LexOrdering::new(vec![PhysicalSortExpr::new(
+ physical_col(range_column, projected_schema)?,
+ SortOptions::default(),
+ )])
+ .expect("range ordering should not be empty");
+
+ Ok(Partitioning::Range(RangePartitioning::try_new(
+ ordering,
+ self.split_points.clone(),
+ )?))
+ }
+}
+
+fn projected_index(
+ column_index: usize,
+ projection: Option<&Vec<usize>>,
+) -> Option<usize> {
+ projection
+ .map(|projection| projection.iter().position(|idx| *idx ==
column_index))
+ .unwrap_or(Some(column_index))
+}
+
+#[derive(Clone, Debug)]
+struct RangePartitionedSource {
+ inner: MemorySourceConfig,
+ output_partitioning: Partitioning,
+}
+
+impl DataSource for RangePartitionedSource {
+ fn open(
+ &self,
+ partition: usize,
+ context: Arc<TaskContext>,
+ ) -> Result<SendableRecordBatchStream> {
+ self.inner.open(partition, context)
+ }
+
+ fn fmt_as(&self, t: DisplayFormatType, f: &mut fmt::Formatter) ->
fmt::Result {
+ self.inner.fmt_as(t, f)?;
+ match t {
+ DisplayFormatType::Default | DisplayFormatType::Verbose => {
+ write!(f, ", output_partitioning={}", self.output_partitioning)
+ }
+ DisplayFormatType::TreeRender => Ok(()),
+ }
+ }
+
+ fn output_partitioning(&self) -> Partitioning {
+ self.output_partitioning.clone()
+ }
+
+ fn eq_properties(&self) -> EquivalenceProperties {
+ self.inner.eq_properties()
+ }
+
+ fn scheduling_type(&self) -> SchedulingType {
+ self.inner.scheduling_type()
+ }
+
+ fn partition_statistics(&self, partition: Option<usize>) ->
Result<Arc<Statistics>> {
+ self.inner.partition_statistics(partition)
+ }
+
+ fn with_fetch(&self, limit: Option<usize>) -> Option<Arc<dyn DataSource>> {
+ Some(Arc::new(Self {
+ inner: self.inner.clone().with_limit(limit),
+ output_partitioning: self.output_partitioning.clone(),
+ }))
+ }
+
+ fn fetch(&self) -> Option<usize> {
+ self.inner.fetch()
+ }
+
+ fn try_swapping_with_projection(
+ &self,
+ _projection: &ProjectionExprs,
+ ) -> Result<Option<Arc<dyn DataSource>>> {
+ // Range partitioning metadata is projection-sensitive. This fixture
+ // computes it in TableProvider::scan, so do not rewrite later
+ // ProjectionExec nodes into the source.
+ Ok(None)
+ }
+}
+
+fn register_range_partitioned_table(ctx: &SessionContext) {
Review Comment:
yes I think its feasbile and would be useful for future PRs. Ditto to my
comment about this being as simple as possible
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]