avantgardnerio commented on code in PR #5835:
URL: https://github.com/apache/arrow-datafusion/pull/5835#discussion_r1155399901
##########
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 {
+ name: self.object_name_to_table_reference(name)?,
+ primary_key: vec![],
+ input: Arc::new(plan),
+ if_not_exists,
+ or_replace,
+ }))
+ }
- None => {
- let schema =
self.build_schema(columns)?.to_dfschema_ref()?;
- let plan = EmptyRelation {
- produce_one_row: false,
- schema,
- };
- let plan = LogicalPlan::EmptyRelation(plan);
-
- Ok(LogicalPlan::CreateMemoryTable(CreateMemoryTable {
- name: self.object_name_to_table_reference(name)?,
- input: Arc::new(plan),
- if_not_exists,
- or_replace,
- }))
- }
+ None => {
+ let pk: Option<Vec<Ident>> = constraints
+ .iter()
+ .filter_map(|c: &TableConstraint| match c {
+ TableConstraint::Unique {
+ columns,
+ is_primary,
+ ..
+ } => match is_primary {
+ true => Some(columns),
+ false => None,
+ },
+ TableConstraint::ForeignKey { .. } => None,
+ TableConstraint::Check { .. } => None,
+ TableConstraint::Index { .. } => None,
+ TableConstraint::FulltextOrSpatial { .. } => None,
Review Comment:
Should I throw the original error if these are set?
--
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]