You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2024/07/17 04:17:48 UTC

(impala) branch master updated (f1133acc2 -> 5c4e77124)

This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


    from f1133acc2 IMPALA-13088, IMPALA-13109: Use RoaringBitmap instead of sorted vector of int64s
     new 3de8c2ab9 IMPALA-13227: test_spilling_hash_join should be marked for serial execution
     new a486305a9 IMPALA-13209: Optimize ConvertRowBatchTime in ExchangeNode
     new 5c4e77124 IMPALA-13161: Fix column index overflow in DelimitedTextParser

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 be/src/exec/delimited-text-parser.inline.h |  4 +++-
 be/src/exec/exchange-node.cc               | 33 +++++++++++++++---------------
 be/src/runtime/row-batch.cc                | 25 ++++++++++++++++++++++
 be/src/runtime/row-batch.h                 |  6 ++++++
 tests/query_test/test_delimited_text.py    | 16 +++++++++++++++
 tests/query_test/test_join_queries.py      |  5 ++++-
 6 files changed, 71 insertions(+), 18 deletions(-)


(impala) 02/03: IMPALA-13209: Optimize ConvertRowBatchTime in ExchangeNode

Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit a486305a922d672f77ff23b5f42e604a720597fd
Author: Csaba Ringhofer <cs...@cloudera.com>
AuthorDate: Thu Jul 11 08:48:43 2024 +0200

    IMPALA-13209: Optimize ConvertRowBatchTime in ExchangeNode
    
    The patch optimizes the most common case when the src and dst
    RowBatches have the same number of tuples per row.
    
    ConvertRowBatchTime is decreased from >600ms to <100ms in a query
    with busy exchange node:
    set mt_dop=8;
    select straight_join count(*) from tpcds_parquet.store_sales s1
      join /*+broadcast*/ tpcds_parquet.store_sales16 s2
      on s1.ss_customer_sk = s2.ss_customer_sk;
    
    TPCDS-20 showed minor improvement (0.77%). The affect is likely to
    be larger if more nodes are involved.
    
    Testing:
    - passed core tests
    
    Change-Id: Iab94315364e8886da1ae01cf6af623812a2da9cb
    Reviewed-on: http://gerrit.cloudera.org:8080/21571
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exec/exchange-node.cc | 33 +++++++++++++++++----------------
 be/src/runtime/row-batch.cc  | 25 +++++++++++++++++++++++++
 be/src/runtime/row-batch.h   |  6 ++++++
 3 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/be/src/exec/exchange-node.cc b/be/src/exec/exchange-node.cc
index b605ba0a7..7faa02261 100644
--- a/be/src/exec/exchange-node.cc
+++ b/be/src/exec/exchange-node.cc
@@ -202,23 +202,24 @@ Status ExchangeNode::GetNext(RuntimeState* state, RowBatch* output_batch, bool*
       SCOPED_TIMER(convert_row_batch_timer_);
       RETURN_IF_CANCELLED(state);
       RETURN_IF_ERROR(QueryMaintenance(state));
-      // copy rows until we hit the limit/capacity or until we exhaust input_batch_
-      while (!ReachedLimit() && !output_batch->AtCapacity()
-          && input_batch_ != NULL && next_row_idx_ < input_batch_->num_rows()) {
-        TupleRow* src = input_batch_->GetRow(next_row_idx_);
-        ++next_row_idx_;
-        int j = output_batch->AddRow();
-        TupleRow* dest = output_batch->GetRow(j);
-        // if the input row is shorter than the output row, make sure not to leave
-        // uninitialized Tuple* around
-        output_batch->ClearRow(dest);
-        // this works as expected if rows from input_batch form a prefix of
-        // rows in output_batch
-        input_batch_->CopyRow(src, dest);
-        output_batch->CommitLastRow();
-        IncrementNumRowsReturned(1);
+      if (input_batch_ != nullptr) {
+        // copy rows until we hit the limit/capacity or until we exhaust input_batch_
+        int available_in_input = input_batch_->num_rows() - next_row_idx_;
+        int free_in_output = output_batch->capacity() - output_batch->num_rows();
+        int rows_to_copy = std::min(available_in_input, free_in_output);
+        if (limit_ != -1) {
+          rows_to_copy =
+              static_cast<int>(std::min<int64_t>(rows_to_copy, limit_ - rows_returned()));
+        }
+        if (rows_to_copy > 0) {
+          int dst_offset = output_batch->AddRows(rows_to_copy);
+          output_batch->CopyRows(input_batch_, rows_to_copy, next_row_idx_, dst_offset);
+          next_row_idx_ += rows_to_copy;
+          output_batch->CommitRows(rows_to_copy);
+          IncrementNumRowsReturned(rows_to_copy);
+          COUNTER_SET(rows_returned_counter_, rows_returned());
+        }
       }
-      COUNTER_SET(rows_returned_counter_, rows_returned());
 
       if (ReachedLimit()) {
         ReleaseRecvrResources(output_batch);
diff --git a/be/src/runtime/row-batch.cc b/be/src/runtime/row-batch.cc
index a8b4a7730..848fcdca7 100644
--- a/be/src/runtime/row-batch.cc
+++ b/be/src/runtime/row-batch.cc
@@ -545,4 +545,29 @@ void RowBatch::VLogRows(const string& context) {
   }
 }
 
+void RowBatch::CopyRows(RowBatch* src, int num_rows, int src_offset, int dst_offset) {
+  DCHECK_GT(num_rows, 0);
+  DCHECK_GE(num_tuples_per_row_, src->num_tuples_per_row_);
+  DCHECK_GE(src_offset, 0);
+  DCHECK_GE(dst_offset, 0);
+  DCHECK_GE(capacity_, num_rows + dst_offset);
+  DCHECK_GE(src->num_rows_, num_rows + src_offset);
+  bool same_layout = num_tuples_per_row_ == src->num_tuples_per_row_;
+  if (same_layout) {
+    // Fast path, single copy.
+    TupleRow* dst_row = GetRow(dst_offset);
+    TupleRow* src_row = src->GetRow(src_offset);
+    memcpy(dst_row, src_row, num_rows * num_tuples_per_row_ * sizeof(Tuple*));
+    return;
+  }
+  // Slow path, null tuples and copy prefixes.
+  DCHECK_GT(num_tuples_per_row_, src->num_tuples_per_row_);
+  for (int i = 0; i < num_rows; i++) {
+    TupleRow* dst_row = GetRow(dst_offset + i);
+    TupleRow* src_row = src->GetRow(src_offset + i);
+    ClearRow(dst_row);
+    src->CopyRow(src_row, dst_row);
+  }
+}
+
 } // namespace impala
diff --git a/be/src/runtime/row-batch.h b/be/src/runtime/row-batch.h
index 3626d7dce..76c580319 100644
--- a/be/src/runtime/row-batch.h
+++ b/be/src/runtime/row-batch.h
@@ -292,6 +292,12 @@ class RowBatch {
     memcpy(dest, src, num_tuples_per_row_ * sizeof(Tuple*));
   }
 
+  /// Copies tuple pointers from another row batch. It is allowed for 'src' to have
+  /// less tuples per row - in this case the prefix is copied and remaining tuples are
+  /// initialized to 0. The caller must ensure that src has enough rows / dst has enough
+  /// capacity.
+  void CopyRows(RowBatch* src, int num_rows, int src_offset, int dst_offset);
+
   /// Copy 'num_rows' rows from 'src' to 'dest' within the batch. Useful for exec
   /// nodes that skip an offset and copied more than necessary.
   void CopyRows(int64_t dest, int64_t src, int64_t num_rows) {


(impala) 03/03: IMPALA-13161: Fix column index overflow in DelimitedTextParser

Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 5c4e771241a7f847d2349ae248bc268243e071ed
Author: stiga-huang <hu...@gmail.com>
AuthorDate: Sun Jun 30 21:17:40 2024 +0800

    IMPALA-13161: Fix column index overflow in DelimitedTextParser
    
    DelimitedTextParser tracks the current column index inside the current
    row that is under parsing. The row could have arbitrary numbers of
    fields. The index, 'column_idx_', is defined as int type which could
    overflow when there are more than 2^31 fields in the row. This index is
    only used to check whether the current column should be materialized. It
    doesn't make sense to track the index if it's larger than the number of
    columns of the table.
    
    This patch fixes the overflow issue by only bumping 'column_idx_' when
    it's smaller than the number of columns of the table.
    
    Tests
     - Add e2e test
    
    Change-Id: I527a8971e92e270d5576c2155e4622dd6d43d745
    Reviewed-on: http://gerrit.cloudera.org:8080/21559
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exec/delimited-text-parser.inline.h |  4 +++-
 tests/query_test/test_delimited_text.py    | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/be/src/exec/delimited-text-parser.inline.h b/be/src/exec/delimited-text-parser.inline.h
index aa6b5c4bd..86e5e3f4e 100644
--- a/be/src/exec/delimited-text-parser.inline.h
+++ b/be/src/exec/delimited-text-parser.inline.h
@@ -71,7 +71,9 @@ inline Status DelimitedTextParser<DELIMITED_TUPLES>::AddColumn(int64_t len,
   }
   if (PROCESS_ESCAPES) current_column_has_escape_ = false;
   *next_column_start += len + 1;
-  ++column_idx_;
+  // No need to keep bumping 'column_idx_' if it's already 'num_cols_'. Otherwise,
+  // a large file with full of field delimiters might lead to 'column_idx_' overflow.
+  if (column_idx_ < num_cols_) ++column_idx_;
   return Status::OK();
 }
 
diff --git a/tests/query_test/test_delimited_text.py b/tests/query_test/test_delimited_text.py
index 34bd93e04..8fb5b3d4b 100644
--- a/tests/query_test/test_delimited_text.py
+++ b/tests/query_test/test_delimited_text.py
@@ -20,6 +20,7 @@
 #
 
 from __future__ import absolute_import, division, print_function
+from subprocess import check_call
 from tests.common.impala_test_suite import ImpalaTestSuite
 from tests.common.test_dimensions import (
     create_single_exec_option_dimension,
@@ -77,3 +78,18 @@ class TestDelimitedText(ImpalaTestSuite):
     cleanup/setup"""
     self.run_test_case('QueryTest/delimited-latin-text', vector, unique_database,
       encoding="latin-1")
+
+  def test_large_file_of_field_delimiters(self, vector, unique_database):
+    """IMPALA-13161: Verifies reading a large file which has full of field delimiters
+       won't causing crash due to overflows"""
+    tbl = unique_database + ".tbl"
+    self.execute_query("create table {}(i int)".format(tbl))
+    table_loc = self._get_table_location(tbl, vector)
+    # Generate a 3GB data file that has full of '\x00' (the default field delimiter)
+    with open("data.txt", "wb") as f:
+      long_str = "\x00" * 1024 * 1024 * 3
+      [f.write(long_str) for i in range(1024)]
+    check_call(["hdfs", "dfs", "-put", "data.txt", table_loc])
+    self.execute_query("refresh " + tbl)
+    res = self.execute_query("select count(*) from " + tbl)
+    assert res.data == ["1"]


(impala) 01/03: IMPALA-13227: test_spilling_hash_join should be marked for serial execution

Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 3de8c2ab9c755b1adfc35ea2176a2ac193899ca6
Author: Zoltan Borok-Nagy <bo...@cloudera.com>
AuthorDate: Mon Jul 15 19:49:13 2024 +0200

    IMPALA-13227: test_spilling_hash_join should be marked for serial execution
    
    test_spilling_hash_join consumes too much resources and parallel
    tests can fail because of it. We should mark it for serial execution.
    
    Testing:
     * had a green exhaustive run, and we also now that before
       test_spilling_hash_join was added, the exhaustive runs
       were much stable
    
    Change-Id: I7b50376db9dde5b33a02fde55880f49a7db4b7c1
    Reviewed-on: http://gerrit.cloudera.org:8080/21589
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 tests/query_test/test_join_queries.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/query_test/test_join_queries.py b/tests/query_test/test_join_queries.py
index 10939ab4f..90105af7c 100644
--- a/tests/query_test/test_join_queries.py
+++ b/tests/query_test/test_join_queries.py
@@ -214,8 +214,11 @@ class TestSpillingHashJoin(ImpalaTestSuite):
     if cls.exploration_strategy() != 'exhaustive':
       cls.ImpalaTestMatrix.add_constraint(lambda v: False)
     cls.ImpalaTestMatrix.add_constraint(
-      lambda v: v.get_value('table_format').file_format == 'parquet')
+        lambda v: v.get_value('table_format').file_format == 'parquet')
+    cls.ImpalaTestMatrix.add_constraint(lambda v:
+        v.get_value('exec_option')['disable_codegen'] is False)
 
+  @pytest.mark.execute_serially
   def test_spilling_hash_join(self, vector, unique_database):
     """Regression test for IMPALA-13138. It loads a few large tables and runs a complex
     query that spills during JOIN build that crashed Impala before IMPALA-13138."""