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


##########
datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs:
##########
@@ -148,19 +148,52 @@ pub async fn from_read_rel(
             let values = if !vt.expressions.is_empty() {
                 let mut exprs = 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()
+                        );
+                    }
+
                     let mut row_exprs = vec![];
-                    for expression in &row.fields {
-                        let expr = consumer
-                            .consume_expression(expression, &substrait_schema)
-                            .await?;
+                    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)) => {
+                                if !named_struct.names.is_empty() {
+                                    name_idx += 1; // top-level names are 
provided through schema
+                                }
+                                Expr::Literal(
+                                    from_substrait_literal(
+                                        consumer,
+                                        lit,
+                                        &named_struct.names,
+                                        &mut name_idx,
+                                    )?,
+                                    None,
+                                )

Review Comment:
   For reviewers, without this code for handling `RexType::Literal` we see the 
following snapshot error:
   ```
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Snapshot: roundtrip_values
   Source: datafusion/substrait/tests/cases/roundtrip_logical_plan.rs:1519
   
────────────────────────────────────────────────────────────────────────────────
   Expression: plan
   
────────────────────────────────────────────────────────────────────────────────
   -old snapshot
   +new results
   
────────────┬───────────────────────────────────────────────────────────────────
       1       │-Values: (Int64(1), Utf8("a"), List([[-213.1, , 5.5, 2.0, 1.0], 
[]]), LargeList([1, 2, 3]), Struct({c0:true,int_field:1,c2:}), 
List([{struct_field: {string_field: a}}, {struct_field: {string_field: b}}])), 
(Int64(NULL), Utf8(NULL), List(), LargeList(), Struct({c0:,int_field:,c2:}), 
List())
             1 │+Values: (Int64(1), Utf8("a"), List([[-213.1, , 5.5, 2.0, 1.0], 
[]]), LargeList([1, 2, 3]), Struct({c0:true,c1:1,c2:}), List([{c0: {c0: a}}, 
{c0: {c0: b}}])), (Int64(NULL), Utf8(NULL), List(), LargeList(), 
Struct({c0:,c1:,c2:}), List())
   
────────────┴───────────────────────────────────────────────────────────────────
   ```
   
   Effectively, names of struct fields don't roundtrip properly without this 
handling.



##########
datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs:
##########
@@ -148,19 +148,52 @@ pub async fn from_read_rel(
             let values = if !vt.expressions.is_empty() {
                 let mut exprs = 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()
+                        );
+                    }
+
                     let mut row_exprs = vec![];
-                    for expression in &row.fields {
-                        let expr = consumer
-                            .consume_expression(expression, &substrait_schema)
-                            .await?;
+                    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)) => {
+                                if !named_struct.names.is_empty() {
+                                    name_idx += 1; // top-level names are 
provided through schema
+                                }

Review Comment:
   Do we actually need this increment to be in a conditional? Nothing breaks if 
we remove the conditional check.
   
   I assume that the handling in this section is cribbing from the existing 
literal handling code in
   
https://github.com/apache/datafusion/blob/d61d31a8fae9f6b572d896b539ea410728c1aa6e/datafusion/substrait/src/logical_plan/consumer/rel/read_rel.rs#L239-L252
   which also doesn't have this check.



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