You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/02/23 16:05:13 UTC

[doris] branch branch-1.2-lts updated (6057ba6a4f -> df4672e9f1)

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

morningman pushed a change to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


    from 6057ba6a4f [cherrypick](planner) remove useless datev2 and decimalv3 conversion in FuntionCallExpr (#17067)
     new e041fa5b81 [fix](planner) Nullable of slot descriptor is mistaken and cause BE crash #16862
     new 5002f5adcb [fix](merge-on-write) add check for segment num (#14032)
     new f47edb9318 [fix](tvf) fix bug that failed to get schema of tvf when file is empty (#16928)
     new 2031625d13 [BugFix](Jdbc Catalog) Fix null pointer exception in JdbcExecutor (#16958)
     new df4672e9f1 [enhancement](cache) make segment cache prune more effectively (#17011)

The 5 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/common/config.h                             |   2 +-
 be/src/olap/lru_cache.cpp                          |  10 +-
 be/src/olap/lru_cache.h                            |   6 +-
 be/src/olap/rowset/beta_rowset_writer.cpp          |   2 +-
 be/src/olap/segment_loader.cpp                     |   3 +-
 be/src/service/internal_service.cpp                |   6 +-
 be/src/vec/exec/format/csv/csv_reader.cpp          |   4 +-
 be/src/vec/exec/format/orc/vorc_reader.cpp         |  11 +-
 be/src/vec/exec/format/parquet/vparquet_reader.cpp |   8 +-
 be/src/vec/exec/scan/vfile_scanner.cpp             |   4 +-
 be/test/olap/lru_cache_test.cpp                    |  50 ++++
 .../org/apache/doris/external/jdbc/JdbcClient.java |  18 +-
 .../org/apache/doris/planner/SetOperationNode.java |  12 +
 .../java/org/apache/doris/udf/JdbcExecutor.java    | 297 ++++++++++++++-------
 .../test_set_operator.out}                         |  14 +-
 .../query_p0/operator/test_set_operator.groovy     |  91 +++++++
 16 files changed, 392 insertions(+), 146 deletions(-)
 copy regression-test/data/query_p0/{intersect/test_intersect.out => operator/test_set_operator.out} (84%)
 create mode 100644 regression-test/suites/query_p0/operator/test_set_operator.groovy


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[doris] 02/05: [fix](merge-on-write) add check for segment num (#14032)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 5002f5adcb54a3907d384f98d7e2eee5e9e83276
Author: zhannngchen <48...@users.noreply.github.com>
AuthorDate: Mon Feb 20 11:01:34 2023 +0800

    [fix](merge-on-write) add check for segment num (#14032)
---
 be/src/olap/rowset/beta_rowset_writer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/be/src/olap/rowset/beta_rowset_writer.cpp b/be/src/olap/rowset/beta_rowset_writer.cpp
index a18d8c5f67..100d85e452 100644
--- a/be/src/olap/rowset/beta_rowset_writer.cpp
+++ b/be/src/olap/rowset/beta_rowset_writer.cpp
@@ -849,7 +849,7 @@ void BetaRowsetWriter::_build_rowset_meta(std::shared_ptr<RowsetMeta> rowset_met
     }
 
     rowset_meta->set_num_segments(num_seg);
-    // TODO(zhangzhengyu): key_bounds.size() should equal num_seg, but currently not always
+    CHECK_EQ(num_seg, segments_encoded_key_bounds.size());
     rowset_meta->set_num_rows(num_rows_written + _num_rows_written);
     rowset_meta->set_total_disk_size(total_data_size + _total_data_size);
     rowset_meta->set_data_disk_size(total_data_size + _total_data_size);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[doris] 04/05: [BugFix](Jdbc Catalog) Fix null pointer exception in JdbcExecutor (#16958)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 2031625d139ee045406ec78f41920d88be402906
Author: Tiewei Fang <43...@users.noreply.github.com>
AuthorDate: Thu Feb 23 14:04:54 2023 +0800

    [BugFix](Jdbc Catalog) Fix null pointer exception in JdbcExecutor (#16958)
    
    This pr do two things:
    1. fix:
        It use `column[0]` to judge class type in JdbcExecutor, but column[0] may be null !
    
    2. Enhencement
        In the original logic, all fields in jdbc catalog table will be set Nullable.
        However, it is inefficient for nullable fields. Actually, we can know if the fields in data source table
        is nullable through jdbc. So we can set the corresponding fields in Doris jdbc catalog to nullable or not.
---
 .../org/apache/doris/external/jdbc/JdbcClient.java |  18 +-
 .../java/org/apache/doris/udf/JdbcExecutor.java    | 297 ++++++++++++++-------
 2 files changed, 203 insertions(+), 112 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
index e5a925557f..98f8b0581a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
@@ -264,13 +264,7 @@ public class JdbcClient {
         // for utf8 encoding, if columnSize=10, then charOctetLength=30
         // because for utf8 encoding, a Chinese character takes up 3 bytes
         private int charOctetLength;
-        /**
-         *  Whether it is allowed to be NULL
-         *  0 (columnNoNulls)
-         *  1 (columnNullable)
-         *  2 (columnNullableUnknown)
-         */
-        private int nullAble;
+        private boolean isAllowNull;
     }
 
     /**
@@ -312,7 +306,13 @@ public class JdbcClient {
                 field.setColumnSize(rs.getInt("COLUMN_SIZE"));
                 field.setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
                 field.setNumPrecRadix(rs.getInt("NUM_PREC_RADIX"));
-                field.setNullAble(rs.getInt("NULLABLE"));
+                /**
+                 *  Whether it is allowed to be NULL
+                 *  0 (columnNoNulls)
+                 *  1 (columnNullable)
+                 *  2 (columnNullableUnknown)
+                 */
+                field.setAllowNull(rs.getInt("NULLABLE") == 0 ? false : true);
                 field.setRemarks(rs.getString("REMARKS"));
                 field.setCharOctetLength(rs.getInt("CHAR_OCTET_LENGTH"));
                 tableSchema.add(field);
@@ -684,7 +684,7 @@ public class JdbcClient {
         for (JdbcFieldSchema field : jdbcTableSchema) {
             dorisTableSchema.add(new Column(field.getColumnName(),
                     jdbcTypeToDoris(field), true, null,
-                    true, field.getRemarks(),
+                    field.isAllowNull(), field.getRemarks(),
                     true, -1));
         }
         return dorisTableSchema;
diff --git a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
index 3e4073196e..df30b8e1b5 100644
--- a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
+++ b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
@@ -259,9 +259,9 @@ public class JdbcExecutor {
     }
 
     private void bigDecimalPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -278,9 +278,9 @@ public class JdbcExecutor {
     }
 
     private void integerPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -295,9 +295,9 @@ public class JdbcExecutor {
     }
 
     private void shortPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -314,19 +314,26 @@ public class JdbcExecutor {
     public void copyBatchTinyIntResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Integer) {
-            integerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Short) {
-            shortPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Integer) {
+            integerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Short) {
+            shortPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
     private void bigDecimalPutToShort(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -341,9 +348,9 @@ public class JdbcExecutor {
     }
 
     private void integerPutToShort(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -358,9 +365,9 @@ public class JdbcExecutor {
     }
 
     private void shortPutToShort(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -377,20 +384,27 @@ public class JdbcExecutor {
     public void copyBatchSmallIntResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Integer) {
-            integerPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Short) {
-            shortPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Integer) {
+            integerPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Short) {
+            shortPutToShort(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
 
     private void bigDecimalPutToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -405,9 +419,9 @@ public class JdbcExecutor {
     }
 
     private void integerPutToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -424,17 +438,24 @@ public class JdbcExecutor {
     public void copyBatchIntResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Integer) {
-            integerPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Integer) {
+            integerPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
     private void bigDecimalPutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -449,9 +470,9 @@ public class JdbcExecutor {
     }
 
     private void longPutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -468,15 +489,22 @@ public class JdbcExecutor {
     public void copyBatchBigIntResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Long) {
-            longPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Long) {
+            longPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
     private void bigDecimalPutToBigInteger(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         BigInteger[] data = new BigInteger[numRows];
         for (int i = 0; i < numRows; i++) {
             if (column[i] == null) {
@@ -486,13 +514,13 @@ public class JdbcExecutor {
                 data[i] = ((BigDecimal) column[i]).toBigInteger();
             }
         }
-        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
+        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16, startRowForNullable);
     }
 
     private void bigIntegerPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable == true) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -527,10 +555,17 @@ public class JdbcExecutor {
     public void copyBatchLargeIntResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToBigInteger(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof BigInteger) {
-            bigIntegerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToBigInteger(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof BigInteger) {
+            bigIntegerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
@@ -553,9 +588,9 @@ public class JdbcExecutor {
     }
 
     private void bigDecimalPutToDouble(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -571,9 +606,9 @@ public class JdbcExecutor {
 
 
     private void doublePutToDouble(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -590,10 +625,17 @@ public class JdbcExecutor {
     public void copyBatchDoubleResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof BigDecimal) {
-            bigDecimalPutToDouble(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Double) {
-            doublePutToDouble(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof BigDecimal) {
+            bigDecimalPutToDouble(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Double) {
+            doublePutToDouble(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
@@ -613,9 +655,9 @@ public class JdbcExecutor {
     }
 
     private void localDatePutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -636,9 +678,9 @@ public class JdbcExecutor {
     }
 
     private void datePutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -661,17 +703,24 @@ public class JdbcExecutor {
     public void copyBatchDateResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof LocalDate) {
-            localDatePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Date) {
-            datePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof LocalDate) {
+            localDatePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Date) {
+            datePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
     private void localDatePutToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -692,9 +741,9 @@ public class JdbcExecutor {
     }
 
     private void datePutToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -715,10 +764,17 @@ public class JdbcExecutor {
     public void copyBatchDateV2Result(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof LocalDate) {
-            localDatePutToInt(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof Date) {
-            datePutToInt(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof LocalDate) {
+            localDatePutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof Date) {
+            datePutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
@@ -747,9 +803,9 @@ public class JdbcExecutor {
     }
 
     private void localDateTimePutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -772,9 +828,9 @@ public class JdbcExecutor {
     }
 
     private void timestampPutToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -796,9 +852,9 @@ public class JdbcExecutor {
 
     private void oracleTimetampPutToLong(Object[] column, boolean isNullable, int numRows,
             long nullMapAddr,
-            long columnAddr) throws SQLException {
+            long columnAddr, int startRowForNullable) throws SQLException {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -821,19 +877,26 @@ public class JdbcExecutor {
     public void copyBatchDateTimeResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) throws SQLException {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof LocalDateTime) {
-            localDateTimePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof java.sql.Timestamp) {
-            timestampPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof oracle.sql.TIMESTAMP) {
-            oracleTimetampPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof LocalDateTime) {
+            localDateTimePutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof java.sql.Timestamp) {
+            timestampPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof oracle.sql.TIMESTAMP) {
+            oracleTimetampPutToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
     private void localDateTimePutToLongV2(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -856,9 +919,9 @@ public class JdbcExecutor {
     }
 
     private void timestampPutToLongV2(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
-            long columnAddr) {
+            long columnAddr, int startRowForNullable) {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -879,9 +942,9 @@ public class JdbcExecutor {
     }
 
     private void oracleTimetampPutToLongV2(Object[] column, boolean isNullable, int numRows,
-            long nullMapAddr, long columnAddr) throws SQLException {
+            long nullMapAddr, long columnAddr, int startRowForNullable) throws SQLException {
         if (isNullable) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] == null) {
                     UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
                 } else {
@@ -904,12 +967,19 @@ public class JdbcExecutor {
     public void copyBatchDateTimeV2Result(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long columnAddr) throws SQLException {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof LocalDateTime) {
-            localDateTimePutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof java.sql.Timestamp) {
-            timestampPutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr);
-        } else if (column[0] instanceof oracle.sql.TIMESTAMP) {
-            oracleTimetampPutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr);
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof LocalDateTime) {
+            localDateTimePutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof java.sql.Timestamp) {
+            timestampPutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
+        } else if (column[firstNotNullIndex] instanceof oracle.sql.TIMESTAMP) {
+            oracleTimetampPutToLongV2(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
         }
     }
 
@@ -942,6 +1012,8 @@ public class JdbcExecutor {
         byte[][] byteRes = new byte[numRows][];
         int offset = 0;
         if (isNullable == true) {
+            // Here can not loop from startRowForNullable,
+            // because byteRes will be used later
             for (int i = 0; i < numRows; i++) {
                 if (column[i] == null) {
                     byteRes[i] = emptyBytes;
@@ -1009,7 +1081,14 @@ public class JdbcExecutor {
     public void copyBatchStringResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
             long offsetsAddr, long charsAddr) {
         Object[] column = (Object[]) columnObj;
-        if (column[0] instanceof String) {
+        int firstNotNullIndex = 0;
+        if (isNullable) {
+            firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
+        }
+        if (firstNotNullIndex == numRows) {
+            return;
+        }
+        if (column[firstNotNullIndex] instanceof String) {
             stringPutToString(column, isNullable, numRows, nullMapAddr, offsetsAddr, charsAddr);
         } else {
             //object like in pg type point, polygon, jsonb..... get object is org.postgresql.util.PGobject.....
@@ -1030,7 +1109,7 @@ public class JdbcExecutor {
                 data[i] = ((BigDecimal) column[i]).setScale(9, RoundingMode.HALF_EVEN).unscaledValue();
             }
         }
-        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
+        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16, 0);
     }
 
     public void copyBatchDecimal32Result(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
@@ -1045,7 +1124,7 @@ public class JdbcExecutor {
                 data[i] = ((BigDecimal) column[i]).setScale(scale, RoundingMode.HALF_EVEN).unscaledValue();
             }
         }
-        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 4);
+        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 4, 0);
     }
 
     public void copyBatchDecimal64Result(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
@@ -1060,7 +1139,7 @@ public class JdbcExecutor {
                 data[i] = ((BigDecimal) column[i]).setScale(scale, RoundingMode.HALF_EVEN).unscaledValue();
             }
         }
-        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 8);
+        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 8, 0);
     }
 
     public void copyBatchDecimal128Result(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
@@ -1075,13 +1154,13 @@ public class JdbcExecutor {
                 data[i] = ((BigDecimal) column[i]).setScale(scale, RoundingMode.HALF_EVEN).unscaledValue();
             }
         }
-        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
+        copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16, 0);
     }
 
     private void copyBatchDecimalResult(BigInteger[] column, boolean isNullable, int numRows,
-            long columnAddr, int typeLen) {
+            long columnAddr, int typeLen, int startRowForNullable) {
         if (isNullable == true) {
-            for (int i = 0; i < numRows; i++) {
+            for (int i = startRowForNullable; i < numRows; i++) {
                 if (column[i] != null) {
                     byte[] bytes = UdfUtils.convertByteOrder(column[i].toByteArray());
                     byte[] value = new byte[typeLen];
@@ -1110,4 +1189,16 @@ public class JdbcExecutor {
             }
         }
     }
+
+    private int getFirstNotNullObject(Object[] column, int numRows, long nullMapAddr) {
+        int i = 0;
+        for (; i < numRows; ++i) {
+            if (null == column[i]) {
+                UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+            } else {
+                break;
+            }
+        }
+        return i;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[doris] 05/05: [enhancement](cache) make segment cache prune more effectively (#17011)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit df4672e9f1d700cd0b0cc80a72c0815e17aaf24b
Author: zhannngchen <48...@users.noreply.github.com>
AuthorDate: Thu Feb 23 18:24:18 2023 +0800

    [enhancement](cache) make segment cache prune more effectively (#17011)
    
    BloomFilter in MoW table may consume lots of memory, and it's life cycle is same as segment. This patch try to improve the efficiency of recycling segment cache, to release the memory in time.
---
 be/src/common/config.h          |  2 +-
 be/src/olap/lru_cache.cpp       | 10 ++++++---
 be/src/olap/lru_cache.h         |  6 ++---
 be/src/olap/segment_loader.cpp  |  3 ++-
 be/test/olap/lru_cache_test.cpp | 50 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/be/src/common/config.h b/be/src/common/config.h
index 49e8f09983..b278a9c55c 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -216,7 +216,7 @@ CONF_mInt64(memory_limitation_per_thread_for_schema_change_bytes, "2147483648");
 CONF_mInt64(memory_limitation_per_thread_for_storage_migration_bytes, "100000000");
 
 // the clean interval of file descriptor cache and segment cache
-CONF_mInt32(cache_clean_interval, "1800");
+CONF_mInt32(cache_clean_interval, "60");
 CONF_mInt32(disk_stat_monitor_interval, "5");
 CONF_mInt32(unused_rowset_monitor_interval, "30");
 CONF_String(storage_root_path, "${DORIS_HOME}/storage");
diff --git a/be/src/olap/lru_cache.cpp b/be/src/olap/lru_cache.cpp
index 9b4fa21fbc..0eb6fe53bb 100644
--- a/be/src/olap/lru_cache.cpp
+++ b/be/src/olap/lru_cache.cpp
@@ -392,7 +392,7 @@ int64_t LRUCache::prune() {
     return pruned_count;
 }
 
-int64_t LRUCache::prune_if(CacheValuePredicate pred) {
+int64_t LRUCache::prune_if(CacheValuePredicate pred, bool lazy_mode) {
     LRUHandle* to_remove_head = nullptr;
     {
         std::lock_guard<std::mutex> l(_mutex);
@@ -403,6 +403,8 @@ int64_t LRUCache::prune_if(CacheValuePredicate pred) {
                 _evict_one_entry(p);
                 p->next = to_remove_head;
                 to_remove_head = p;
+            } else if (lazy_mode) {
+                break;
             }
             p = next;
         }
@@ -414,6 +416,8 @@ int64_t LRUCache::prune_if(CacheValuePredicate pred) {
                 _evict_one_entry(p);
                 p->next = to_remove_head;
                 to_remove_head = p;
+            } else if (lazy_mode) {
+                break;
             }
             p = next;
         }
@@ -518,10 +522,10 @@ int64_t ShardedLRUCache::prune() {
     return num_prune;
 }
 
-int64_t ShardedLRUCache::prune_if(CacheValuePredicate pred) {
+int64_t ShardedLRUCache::prune_if(CacheValuePredicate pred, bool lazy_mode) {
     int64_t num_prune = 0;
     for (int s = 0; s < _num_shards; s++) {
-        num_prune += _shards[s]->prune_if(pred);
+        num_prune += _shards[s]->prune_if(pred, lazy_mode);
     }
     return num_prune;
 }
diff --git a/be/src/olap/lru_cache.h b/be/src/olap/lru_cache.h
index a6e2f81fb4..8d86fa9b1b 100644
--- a/be/src/olap/lru_cache.h
+++ b/be/src/olap/lru_cache.h
@@ -215,7 +215,7 @@ public:
     // Same as prune(), but the entry will only be pruned if the predicate matched.
     // NOTICE: the predicate should be simple enough, or the prune_if() function
     // may hold lock for a long time to execute predicate.
-    virtual int64_t prune_if(CacheValuePredicate pred) { return 0; }
+    virtual int64_t prune_if(CacheValuePredicate pred, bool lazy_mode = false) { return 0; }
 
     virtual int64_t mem_consumption() = 0;
 
@@ -320,7 +320,7 @@ public:
     void release(Cache::Handle* handle);
     void erase(const CacheKey& key, uint32_t hash);
     int64_t prune();
-    int64_t prune_if(CacheValuePredicate pred);
+    int64_t prune_if(CacheValuePredicate pred, bool lazy_mode = false);
 
     uint64_t get_lookup_count() const { return _lookup_count; }
     uint64_t get_hit_count() const { return _hit_count; }
@@ -374,7 +374,7 @@ public:
     Slice value_slice(Handle* handle) override;
     virtual uint64_t new_id() override;
     virtual int64_t prune() override;
-    virtual int64_t prune_if(CacheValuePredicate pred) override;
+    int64_t prune_if(CacheValuePredicate pred, bool lazy_mode = false) override;
     int64_t mem_consumption() override;
 
 private:
diff --git a/be/src/olap/segment_loader.cpp b/be/src/olap/segment_loader.cpp
index 3e604adf17..fa1e6c8751 100644
--- a/be/src/olap/segment_loader.cpp
+++ b/be/src/olap/segment_loader.cpp
@@ -97,7 +97,8 @@ Status SegmentLoader::prune() {
 
     MonotonicStopWatch watch;
     watch.start();
-    int64_t prune_num = _cache->prune_if(pred);
+    // Prune cache in lazy mode to save cpu and minimize the time holding write lock
+    int64_t prune_num = _cache->prune_if(pred, true);
     LOG(INFO) << "prune " << prune_num
               << " entries in segment cache. cost(ms): " << watch.elapsed_time() / 1000 / 1000;
     return Status::OK();
diff --git a/be/test/olap/lru_cache_test.cpp b/be/test/olap/lru_cache_test.cpp
index c779996c54..83604a26bb 100644
--- a/be/test/olap/lru_cache_test.cpp
+++ b/be/test/olap/lru_cache_test.cpp
@@ -314,6 +314,56 @@ TEST_F(CacheTest, Prune) {
     EXPECT_EQ(0, cache.get_usage());
 }
 
+TEST_F(CacheTest, PruneIfLazyMode) {
+    LRUCache cache(LRUCacheType::NUMBER);
+    cache.set_capacity(10);
+
+    // The lru usage is 1, add one entry
+    CacheKey key1("100");
+    insert_LRUCache(cache, key1, 100, CachePriority::NORMAL);
+    EXPECT_EQ(1, cache.get_usage());
+
+    CacheKey key2("200");
+    insert_LRUCache(cache, key2, 200, CachePriority::DURABLE);
+    EXPECT_EQ(2, cache.get_usage());
+
+    CacheKey key3("300");
+    insert_LRUCache(cache, key3, 300, CachePriority::NORMAL);
+    EXPECT_EQ(3, cache.get_usage());
+
+    CacheKey key4("666");
+    insert_LRUCache(cache, key4, 666, CachePriority::NORMAL);
+    EXPECT_EQ(4, cache.get_usage());
+
+    CacheKey key5("500");
+    insert_LRUCache(cache, key5, 500, CachePriority::NORMAL);
+    EXPECT_EQ(5, cache.get_usage());
+
+    CacheKey key6("600");
+    insert_LRUCache(cache, key6, 600, CachePriority::NORMAL);
+    EXPECT_EQ(6, cache.get_usage());
+
+    CacheKey key7("700");
+    insert_LRUCache(cache, key7, 700, CachePriority::DURABLE);
+    EXPECT_EQ(7, cache.get_usage());
+
+    auto pred = [](const void* value) -> bool { return false; };
+    cache.prune_if(pred, true);
+    EXPECT_EQ(7, cache.get_usage());
+
+    // in lazy mode, the first item not satisfied the pred2, `prune_if` then stopped
+    // and no item's removed.
+    auto pred2 = [](const void* value) -> bool { return DecodeValue((void*)value) > 400; };
+    cache.prune_if(pred2, true);
+    EXPECT_EQ(7, cache.get_usage());
+
+    // in normal priority, 100, 300 are removed
+    // in durable priority, 200 is removed
+    auto pred3 = [](const void* value) -> bool { return DecodeValue((void*)value) <= 600; };
+    EXPECT_EQ(3, cache.prune_if(pred3, true));
+    EXPECT_EQ(4, cache.get_usage());
+}
+
 TEST_F(CacheTest, HeavyEntries) {
     // Add a bunch of light and heavy entries and then count the combined
     // size of items still in the cache, which must be approximately the


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[doris] 03/05: [fix](tvf) fix bug that failed to get schema of tvf when file is empty (#16928)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit f47edb9318fc12cab9662439396e663fe661541b
Author: Mingyu Chen <mo...@163.com>
AuthorDate: Tue Feb 21 14:14:32 2023 +0800

    [fix](tvf) fix bug that failed to get schema of tvf when file is empty (#16928)
    
    In previous implementation, when querying tvf, FE will get schema from BE.
    And BE will try to open the first file to get its schema info, but for orc or parquet format,
    if the file is empty, it will return error.
    But even for an empty file, we can still get schema info from file's footer.
    So we should handle the empty file to get schema info correctly.
    
    Also modify the catalog doc to add some FAQ.
---
 be/src/service/internal_service.cpp                |  6 +++---
 be/src/vec/exec/format/csv/csv_reader.cpp          |  4 ++--
 be/src/vec/exec/format/orc/vorc_reader.cpp         | 11 ++++-------
 be/src/vec/exec/format/parquet/vparquet_reader.cpp |  8 ++------
 be/src/vec/exec/scan/vfile_scanner.cpp             |  4 ++--
 5 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/be/src/service/internal_service.cpp b/be/src/service/internal_service.cpp
index 5922fe6419..aa3510452d 100644
--- a/be/src/service/internal_service.cpp
+++ b/be/src/service/internal_service.cpp
@@ -384,7 +384,8 @@ void PInternalServiceImpl::_tablet_writer_add_batch(google::protobuf::RpcControl
     // this will influence query execution, because the pthreads under bthread may be
     // exhausted, so we put this to a local thread pool to process
     int64_t submit_task_time_ns = MonotonicNanos();
-    bool ret = _heavy_work_pool.offer([cntl_base, request, response, done, submit_task_time_ns, this]() {
+    bool ret = _heavy_work_pool.offer([cntl_base, request, response, done, submit_task_time_ns,
+                                       this]() {
         int64_t wait_execution_time_ns = MonotonicNanos() - submit_task_time_ns;
         brpc::ClosureGuard closure_guard(done);
         int64_t execution_time_ns = 0;
@@ -555,8 +556,7 @@ void PInternalServiceImpl::fetch_table_schema(google::protobuf::RpcController* c
         case TFileFormatType::FORMAT_CSV_DEFLATE: {
             // file_slots is no use
             std::vector<SlotDescriptor*> file_slots;
-            reader.reset(
-                    new vectorized::CsvReader(profile.get(), params, range, file_slots));
+            reader.reset(new vectorized::CsvReader(profile.get(), params, range, file_slots));
             break;
         }
         case TFileFormatType::FORMAT_PARQUET: {
diff --git a/be/src/vec/exec/format/csv/csv_reader.cpp b/be/src/vec/exec/format/csv/csv_reader.cpp
index c7099b24c7..ce537d93cf 100644
--- a/be/src/vec/exec/format/csv/csv_reader.cpp
+++ b/be/src/vec/exec/format/csv/csv_reader.cpp
@@ -115,7 +115,7 @@ Status CsvReader::init_reader(bool is_load) {
     RETURN_IF_ERROR(real_reader->open());
     if (real_reader->size() == 0 && _params.file_type != TFileType::FILE_STREAM &&
         _params.file_type != TFileType::FILE_BROKER) {
-        return Status::EndOfFile("Empty File");
+        return Status::EndOfFile("init reader failed, empty csv file: " + _range.path);
     }
 
     // get column_separator and line_delimiter
@@ -544,7 +544,7 @@ Status CsvReader::_prepare_parse(size_t* read_line, bool* is_parse_name) {
                                                     _range.file_size, 0, _file_reader));
     RETURN_IF_ERROR(_file_reader->open());
     if (_file_reader->size() == 0) {
-        return Status::EndOfFile("Empty File");
+        return Status::EndOfFile("get parsed schema failed, empty csv file: " + _range.path);
     }
 
     // get column_separator and line_delimiter
diff --git a/be/src/vec/exec/format/orc/vorc_reader.cpp b/be/src/vec/exec/format/orc/vorc_reader.cpp
index 57e0b4fc89..0840155203 100644
--- a/be/src/vec/exec/format/orc/vorc_reader.cpp
+++ b/be/src/vec/exec/format/orc/vorc_reader.cpp
@@ -142,7 +142,7 @@ Status OrcReader::init_reader(
         _file_reader = new ORCFileInputStream(_scan_range.path, inner_reader.release());
     }
     if (_file_reader->getLength() == 0) {
-        return Status::EndOfFile("Empty orc file");
+        return Status::EndOfFile("init reader failed, empty orc file: " + _scan_range.path);
     }
 
     // create orc reader
@@ -153,7 +153,8 @@ Status OrcReader::init_reader(
         return Status::InternalError("Init OrcReader failed. reason = {}", e.what());
     }
     if (_reader->getNumberOfRows() == 0) {
-        return Status::EndOfFile("Empty orc file");
+        return Status::EndOfFile("init reader failed, empty orc file with row num 0: " +
+                                 _scan_range.path);
     }
     // _init_bloom_filter(colname_to_value_range);
 
@@ -197,7 +198,7 @@ Status OrcReader::get_parsed_schema(std::vector<std::string>* col_names,
         _file_reader = new ORCFileInputStream(_scan_range.path, inner_reader.release());
     }
     if (_file_reader->getLength() == 0) {
-        return Status::EndOfFile("Empty orc file");
+        return Status::EndOfFile("get parsed schema fail, empty orc file: " + _scan_range.path);
     }
 
     // create orc reader
@@ -208,10 +209,6 @@ Status OrcReader::get_parsed_schema(std::vector<std::string>* col_names,
         return Status::InternalError("Init OrcReader failed. reason = {}", e.what());
     }
 
-    if (_reader->getNumberOfRows() == 0) {
-        return Status::EndOfFile("Empty orc file");
-    }
-
     auto& root_type = _reader->getType();
     for (int i = 0; i < root_type.getSubtypeCount(); ++i) {
         col_names->emplace_back(_get_field_name_lower_case(&root_type, i));
diff --git a/be/src/vec/exec/format/parquet/vparquet_reader.cpp b/be/src/vec/exec/format/parquet/vparquet_reader.cpp
index 35302f9306..d873260010 100644
--- a/be/src/vec/exec/format/parquet/vparquet_reader.cpp
+++ b/be/src/vec/exec/format/parquet/vparquet_reader.cpp
@@ -147,7 +147,7 @@ Status ParquetReader::_open_file() {
     if (_file_metadata == nullptr) {
         RETURN_IF_ERROR(_file_reader->open());
         if (_file_reader->size() == 0) {
-            return Status::EndOfFile("Empty Parquet File");
+            return Status::EndOfFile("open file failed, empty parquet file: " + _scan_range.path);
         }
         RETURN_IF_ERROR(parse_thrift_footer(_file_reader.get(), _file_metadata));
     }
@@ -179,7 +179,7 @@ Status ParquetReader::init_reader(
     SCOPED_RAW_TIMER(&_statistics.parse_meta_time);
     _total_groups = _t_metadata->row_groups.size();
     if (_total_groups == 0) {
-        return Status::EndOfFile("Empty Parquet File");
+        return Status::EndOfFile("init reader failed, empty parquet file: " + _scan_range.path);
     }
     // all_column_names are all the columns required by user sql.
     // missing_column_names are the columns required by user sql but not in the parquet file,
@@ -350,10 +350,6 @@ Status ParquetReader::get_parsed_schema(std::vector<std::string>* col_names,
     _t_metadata = &_file_metadata->to_thrift();
 
     _total_groups = _t_metadata->row_groups.size();
-    if (_total_groups == 0) {
-        return Status::EndOfFile("Empty Parquet File");
-    }
-
     auto schema_desc = _file_metadata->schema();
     for (int i = 0; i < schema_desc.size(); ++i) {
         // Get the Column Reader for the boolean column
diff --git a/be/src/vec/exec/scan/vfile_scanner.cpp b/be/src/vec/exec/scan/vfile_scanner.cpp
index 8619719194..58eb496d71 100644
--- a/be/src/vec/exec/scan/vfile_scanner.cpp
+++ b/be/src/vec/exec/scan/vfile_scanner.cpp
@@ -494,8 +494,8 @@ Status VFileScanner::_get_next_reader() {
                 IcebergTableReader* iceberg_reader =
                         new IcebergTableReader((GenericReader*)parquet_reader, _profile, _state,
                                                _params, range, _kv_cache);
-                iceberg_reader->init_reader(_file_col_names, _col_id_name_map,
-                                            _colname_to_value_range, _push_down_expr);
+                init_status = iceberg_reader->init_reader(_file_col_names, _col_id_name_map,
+                                                          _colname_to_value_range, _push_down_expr);
                 RETURN_IF_ERROR(iceberg_reader->init_row_filters(range));
                 _cur_reader.reset((GenericReader*)iceberg_reader);
             } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[doris] 01/05: [fix](planner) Nullable of slot descriptor is mistaken and cause BE crash #16862

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e041fa5b81ffa896d6bb05af6d423ffaa614f123
Author: AKIRA <33...@users.noreply.github.com>
AuthorDate: Sat Feb 18 20:39:56 2023 +0800

    [fix](planner) Nullable of slot descriptor is mistaken and cause BE crash #16862
---
 .../org/apache/doris/planner/SetOperationNode.java | 12 +++
 .../data/query_p0/operator/test_set_operator.out   | 15 ++++
 .../query_p0/operator/test_set_operator.groovy     | 91 ++++++++++++++++++++++
 3 files changed, 118 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
index 5d806215d4..11760f79b4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
@@ -207,6 +207,18 @@ public abstract class SetOperationNode extends PlanNode {
             }
             materializedConstExprLists.add(newExprList);
         }
+        if (!resultExprLists.isEmpty()) {
+            List<Expr> exprs = resultExprLists.get(0);
+            TupleDescriptor tupleDescriptor = analyzer.getTupleDesc(tupleId);
+            for (int i = 0; i < exprs.size(); i++) {
+                boolean isNullable = exprs.get(i).isNullable();
+                for (int j = 1; j < resultExprLists.size(); j++) {
+                    isNullable = isNullable || resultExprLists.get(j).get(i).isNullable();
+                }
+                tupleDescriptor.getSlots().get(i).setIsNullable(isNullable);
+                tupleDescriptor.computeMemLayout();
+            }
+        }
     }
 
     @Override
diff --git a/regression-test/data/query_p0/operator/test_set_operator.out b/regression-test/data/query_p0/operator/test_set_operator.out
new file mode 100644
index 0000000000..1d8bc5ef93
--- /dev/null
+++ b/regression-test/data/query_p0/operator/test_set_operator.out
@@ -0,0 +1,15 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select --
+1
+1
+3
+4
+5
+5
+5
+51
+6
+7
+9
+9
+
diff --git a/regression-test/suites/query_p0/operator/test_set_operator.groovy b/regression-test/suites/query_p0/operator/test_set_operator.groovy
new file mode 100644
index 0000000000..8a9512e977
--- /dev/null
+++ b/regression-test/suites/query_p0/operator/test_set_operator.groovy
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_set_operators", "query,p0") {
+
+    sql """
+        DROP TABLE IF EXISTS t1;
+    """
+
+    sql """
+        CREATE TABLE t1 (col1 varchar(11451) not null, col2 int not null, col3 int not null)
+        UNIQUE KEY(col1)
+        DISTRIBUTED BY HASH(col1)
+        BUCKETS 3
+        PROPERTIES(
+            "replication_num"="1",
+            "enable_unique_key_merge_on_write"="true"
+        );
+    """
+
+    sql """
+        insert into t1 values(1, 2, 3);
+    """
+
+    sql """insert into t1 values(4, 5, 6);"""
+    sql """insert into t1 values(7, 1, 9);"""
+    sql """insert into t1 values(3, 8, 2);"""
+    sql """insert into t1 values(5, 2, 1);"""
+
+    sql """
+        DROP TABLE IF EXISTS t2;
+    """
+    sql """
+        CREATE TABLE t2 (col1 varchar(32) not null, col2 int not null, col3 int not null, col4 int not null)
+        DISTRIBUTED BY HASH(col3)
+        BUCKETS 3
+        PROPERTIES(
+            "replication_num"="1"
+        );
+    """
+    sql """
+        DROP TABLE IF EXISTS t3;
+    """
+    sql """
+        CREATE TABLE t3 (col1 varchar(32) null, col2 int not null, col3 int not null, col4 int not null)
+        DISTRIBUTED BY HASH(col3)
+        BUCKETS 3
+        PROPERTIES(
+            "replication_num"="1"
+        );
+    """
+
+    sql """insert into t3 values('21',5,1,7);"""
+    sql """insert into t3 values('7',9,1,5);"""
+    sql """insert into t3 values('3',5,3,4);"""
+    sql """insert into t3 values('9',8,0,7);"""
+
+    sql """insert into t2 values('1',5,1,7);"""
+    sql """insert into t2 values('51',9,1,5);"""
+    sql """insert into t2 values('6',5,3,4);"""
+    sql """insert into t2 values('9',8,0,7);"""
+
+    order_qt_select """
+        select
+            col1
+        from
+             t1
+        union all
+        select
+            coalesce(t2.col1, t3.col2)  c
+        from
+            t2
+        full join
+            t3 
+            on t2.col1=t3.col1;
+    """
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org