[ 
https://issues.apache.org/jira/browse/IMPALA-4061?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Arnab Karmakar resolved IMPALA-4061.
------------------------------------
    Target Version: Impala 5.1.0  (was: Product Backlog)
        Resolution: Fixed

> HdfsAvroScanner::CodegenReadRecord() may generate code with unassigned values
> -----------------------------------------------------------------------------
>
>                 Key: IMPALA-4061
>                 URL: https://issues.apache.org/jira/browse/IMPALA-4061
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>    Affects Versions: Impala 2.7.0
>            Reporter: Michael Ho
>            Assignee: Arnab Karmakar
>            Priority: Major
>              Labels: codegen
>
> {noformat}    
>     Value* ret_val;
>     if (field->schema->type == AVRO_RECORD) {
>       BasicBlock* insert_before_block =
>           (null_block != NULL) ? null_block : end_field_block;
>       RETURN_IF_ERROR(CodegenReadRecord(new_path, *field, node, codegen, 
> builder, fn,
>           insert_before_block, bail_out, this_val, pool_val, tuple_val, 
> data_val,
>           data_end_val));
>     } else {
>       RETURN_IF_ERROR(CodegenReadScalar(*field, slot_desc, codegen, builder,
>           this_val, pool_val, tuple_val, data_val, data_end_val, &ret_val));
>     }
>     builder->CreateCondBr(ret_val, end_field_block, bail_out);
> {noformat}
> {{ret_val}} is not assigned in the path CodegenReadRecord(). It appears to 
> only affect nested type with avro only which we don't really support.
> h3. Steps to reproduce
> Spark 4.1.3 + Iceberg 1.11.0 ({{hc}} is a Hadoop catalog):
> {code:sql}
> CREATE TABLE hc.db.struct_mixed (id INT, s STRUCT<a: INT, b: STRING>) USING 
> iceberg
>   TBLPROPERTIES ('format-version'='2');
> INSERT INTO hc.db.struct_mixed VALUES (1, named_struct('a', 10, 'b', 'x1'));  
> -- Parquet
> ALTER TABLE hc.db.struct_mixed SET TBLPROPERTIES 
> ('write.format.default'='avro');
> INSERT INTO hc.db.struct_mixed VALUES (2, named_struct('a', 20, 'b', 'x2')), 
> (3, NULL);  -- Avro
> ALTER TABLE hc.db.struct_mixed SET TBLPROPERTIES 
> ('write.format.default'='parquet');
> CREATE TABLE hc.db.variant_avro (id INT, v VARIANT) USING iceberg
>   TBLPROPERTIES ('format-version'='3', 'write.format.default'='avro');
> INSERT INTO hc.db.variant_avro VALUES (1, parse_json('{"a": 1}')), (2, 
> parse_json('"hello"'));
> {code}
> Impala:
> {code:sql}
> CREATE EXTERNAL TABLE struct_mixed STORED AS ICEBERG
>   LOCATION '<warehouse>/db/struct_mixed' TBLPROPERTIES 
> ('iceberg.catalog'='hadoop.tables');
> CREATE EXTERNAL TABLE variant_avro STORED AS ICEBERG
>   LOCATION '<warehouse>/db/variant_avro' TBLPROPERTIES 
> ('iceberg.catalog'='hadoop.tables');
> -- The tables are tiny; make sure the planner doesn't disable codegen for 
> them.
> SET DISABLE_CODEGEN_ROWS_THRESHOLD=0;
> SET EXEC_SINGLE_NODE_ROWS_THRESHOLD=0;
> SELECT id FROM struct_mixed ORDER BY id;
> SELECT id, s.a FROM struct_mixed ORDER BY id;
> SELECT id FROM variant_avro ORDER BY id;
> {code}
> h3. Expected result
> 1, 2, 3 / (1, 10), (2, 20), (3, NULL) / 1, 2
> h3. Actual result (master e1a2da732c, debug build)
> Each SELECT fails with {{TSocket read 0 bytes}}: the impalads that codegen 
> the Avro scan crash (one to all three of them in our runs), with this stack:
> {noformat}
> #0 llvm::BranchInst::AssertOK()  (lib/IR/Instructions.cpp:1129)
> #1 llvm::IRBuilder<>::CreateCondBr(llvm::Value*, llvm::BasicBlock*, 
> llvm::BasicBlock*, ...)
> #2 impala::HdfsAvroScanner::CodegenReadRecord(...)
> #3 impala::HdfsAvroScanner::CodegenMaterializeTuple(...)
> #4 impala::HdfsAvroScanner::CodegenDecodeAvroData(...)
> #5 impala::HdfsAvroScanner::Codegen(...)
> #7 impala::PlanNode::Codegen(...)
> #8 impala::SortPlanNode::Codegen(...)
> #9 impala::FragmentState::CodegenHelper(...)
> {noformat}
> Release builds link LLVM without assertions, so this check doesn't fire 
> there; I haven't tested what happens instead.
> With {{DISABLE_CODEGEN=true}} the queries don't crash, but {{SELECT id, s.a}} 
> returns (3, 0) instead of (3, NULL), and {{s.b}} returns an empty string for 
> the same row: the null indicators of the fields of a NULL record are not set. 
> This is a separate bug in the Avro scanner.
> h3. Possible fix
> * In {{CodegenReadRecord()}}, branch unconditionally to {{end_field_block}} 
> after the recursive call; the recursion already branches to {{bail_out}} on 
> errors. Alternatively, return an error for record fields so that the scan 
> falls back to the interpreted code, which handles {{SELECT id}} correctly. 
> Reading the fields of a NULL record also needs a fix, in both code paths (see 
> above).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to