avantgardnerio commented on code in PR #5835:
URL: https://github.com/apache/arrow-datafusion/pull/5835#discussion_r1155399820
##########
datafusion/sql/src/statement.rs:
##########
@@ -128,69 +128,91 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if_not_exists,
or_replace,
..
- } if constraints.is_empty()
- && table_properties.is_empty()
- && with_options.is_empty() =>
- {
- match query {
- Some(query) => {
- let plan = self.query_to_plan(*query,
planner_context)?;
- let input_schema = plan.schema();
-
- let plan = if !columns.is_empty() {
- let schema =
self.build_schema(columns)?.to_dfschema_ref()?;
- if schema.fields().len() !=
input_schema.fields().len() {
- return Err(DataFusionError::Plan(format!(
+ } if table_properties.is_empty() && with_options.is_empty() =>
match query {
+ Some(query) => {
+ let plan = self.query_to_plan(*query, planner_context)?;
+ let input_schema = plan.schema();
+
+ let plan = if !columns.is_empty() {
+ let schema =
self.build_schema(columns)?.to_dfschema_ref()?;
+ if schema.fields().len() !=
input_schema.fields().len() {
+ return Err(DataFusionError::Plan(format!(
"Mismatch: {} columns specified, but result has {}
columns",
schema.fields().len(),
input_schema.fields().len()
)));
- }
- let input_fields = input_schema.fields();
- let project_exprs = schema
- .fields()
- .iter()
- .zip(input_fields)
- .map(|(field, input_field)| {
- cast(
- col(input_field.name()),
- field.data_type().clone(),
- )
+ }
+ let input_fields = input_schema.fields();
+ let project_exprs = schema
+ .fields()
+ .iter()
+ .zip(input_fields)
+ .map(|(field, input_field)| {
+ cast(col(input_field.name()),
field.data_type().clone())
.alias(field.name())
- })
- .collect::<Vec<_>>();
- LogicalPlanBuilder::from(plan.clone())
- .project(project_exprs)?
- .build()?
- } else {
- plan
- };
-
- Ok(LogicalPlan::CreateMemoryTable(CreateMemoryTable {
- name: self.object_name_to_table_reference(name)?,
- input: Arc::new(plan),
- if_not_exists,
- or_replace,
- }))
- }
+ })
+ .collect::<Vec<_>>();
+ LogicalPlanBuilder::from(plan.clone())
+ .project(project_exprs)?
+ .build()?
+ } else {
+ plan
+ };
+
+ Ok(LogicalPlan::CreateMemoryTable(CreateMemoryTable {
Review Comment:
Should we rename `CreateMemoryTable` to just `CreateTable`?
--
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]