vbarua commented on code in PR #23672:
URL: https://github.com/apache/datafusion/pull/23672#discussion_r3615618885


##########
datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs:
##########
@@ -114,29 +113,17 @@ pub async fn from_read_rel(
             .await
         }
         Some(ReadType::VirtualTable(vt)) => {
-            if vt.values.is_empty() && vt.expressions.is_empty() {

Review Comment:
   I think we can still check and short-circuit on `vt.expressions.is_empty()` 
here.



##########
datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs:
##########
@@ -145,30 +132,65 @@ pub async fn from_read_rel(
                 }));
             }
 
-            let values = if !vt.expressions.is_empty() {
-                let mut exprs = vec![];
-                for row in &vt.expressions {
-                    let mut row_exprs = vec![];
-                    for expression in &row.fields {
-                        let expr = consumer
-                            .consume_expression(expression, &substrait_schema)
-                            .await?;
-                        row_exprs.push(expr);
-                    }
-                    // For expressions, validate against top-level schema 
fields, not nested names
-                    if row_exprs.len() != substrait_schema.fields().len() {
-                        return substrait_err!(
-                            "Field count mismatch: expected {} fields but 
found {} in virtual table row",
-                            substrait_schema.fields().len(),
-                            row_exprs.len()
-                        );
-                    }
-                    exprs.push(row_exprs);
+            if vt.expressions.is_empty() {
+                return Ok(LogicalPlan::EmptyRelation(EmptyRelation {
+                    produce_one_row: false,
+                    schema: DFSchemaRef::new(substrait_schema),
+                }));
+            }
+
+            let mut values = vec![];
+            for row in &vt.expressions {
+                if row.fields.len() != substrait_schema.fields().len() {
+                    return substrait_err!(
+                        "Field count mismatch: expected {} fields but found {} 
in virtual table row",
+                        substrait_schema.fields().len(),
+                        row.fields.len()
+                    );
                 }
-                exprs
-            } else {
-                convert_literal_rows(consumer, vt, named_struct)?
-            };
+
+                let mut row_exprs = vec![];
+                let mut name_idx = 0;
+                for (field_idx, expression) in row.fields.iter().enumerate() {
+                    let expr = match expression.rex_type.as_ref() {
+                        
Some(substrait::proto::expression::RexType::Literal(lit)) => {

Review Comment:
   Do we actually need to special case the Literal consumer here? I would have 
assumed that `consume_expression` would be able to handle it, and more 
specifically the block in
   ```
   if !vt.expressions.is_empty() {
   ```
   had does everything we needed for the conversion here.
   
   Put another way, it looks like you've inlined some of the 
`convert_literal_rows` code, but I don't think it's needed.



-- 
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]

Reply via email to