You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "loneylee (via GitHub)" <gi...@apache.org> on 2025/04/16 08:15:18 UTC

[PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

loneylee opened a new pull request, #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340

   ## What changes were proposed in this pull request?
   
   (Please fill in changes proposed in this fix)
   
   (Fixes: \#9334)
   
   ## How was this patch tested?
   
   test by ut
   
   


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340#issuecomment-2808771498

   Run Gluten ClickHouse CI on ARM


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340#issuecomment-2809257893

   Run Gluten ClickHouse CI on ARM


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

Posted by "zzcclp (via GitHub)" <gi...@apache.org>.
zzcclp merged PR #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340#issuecomment-2808770539

   <!--
     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/LICEGJ-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.
   -->
   
   Thanks for opening a pull request!
   
   Could you open an issue for this pull request on Github Issues?
   
   https://github.com/apache/incubator-gluten/issues
   
   Then could you also rename ***commit message*** and ***pull request title*** in the following format?
   
       [GLUTEN-${ISSUES_ID}][COMPONENT]feat/fix: ${detailed message}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/incubator-gluten/pulls/)
   
   


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [Gluten-9334][CH] Support delta metadata column `file_path` and `row_index` for mergetree [incubator-gluten]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9340:
URL: https://github.com/apache/incubator-gluten/pull/9340#discussion_r2046693130


##########
cpp-ch/local-engine/Parser/RelParsers/MergeTreeRelParser.cpp:
##########
@@ -66,69 +119,160 @@ static Int64 findMinPosition(const NameSet & condition_table_columns, const Name
     return min_position;
 }
 
-DB::QueryPlanPtr MergeTreeRelParser::parseReadRel(
-    DB::QueryPlanPtr query_plan, const substrait::ReadRel & rel, const substrait::ReadRel::ExtensionTable & extension_table)
-{
-    MergeTreeTableInstance merge_tree_table(extension_table);
-    // ignore snapshot id for a query
-    merge_tree_table.snapshot_id = "";
-    auto storage = merge_tree_table.restoreStorage(QueryContext::globalMutableContext());
 
-    DB::Block input;
-    DB::Block original_input;
+DB::Block MergeTreeRelParser::parseMergeTreeOutput(const substrait::ReadRel & rel, SparkStorageMergeTreePtr storage)
+{
     if (rel.has_base_schema() && rel.base_schema().names_size())
+        return TypeParser::buildBlockFromNamedStruct(rel.base_schema());
+
+    NamesAndTypesList one_column_name_type;
+    one_column_name_type.push_back(storage->getInMemoryMetadataPtr()->getColumns().getAll().front());
+    LOG_DEBUG(getLogger("SerializedPlanParser"), "Try to read ({}) instead of empty header", one_column_name_type.front().dump());
+    return toSampleBlock(one_column_name_type);
+}
+
+
+DB::Block MergeTreeRelParser::replaceDeltaNameIfNeeded(const DB::Block & output)
+{
+    DB::ColumnsWithTypeAndName read_block;
+    for (const auto & column : output)
     {
-        input = TypeParser::buildBlockFromNamedStruct(rel.base_schema());
-        if (input.findByName(FileMetaColumns::INPUT_FILE_NAME) != nullptr)
+        if (DELTA_META_COLUMN_MAP.contains(column.name))
+        {
+            if (auto tuple = DELTA_META_COLUMN_MAP.at(column.name); std::get<0>(tuple).has_value())
+            {
+                auto a= std::get<1>(tuple);
+                read_block.emplace_back(ColumnWithTypeAndName(a, std::get<0>(tuple).value()));
+            }
+
+        }
+        else
         {
-            // mergetree use concat(path, _part) instead of input_file_name
-            input.insert(ColumnWithTypeAndName(ColumnWithTypeAndName(std::make_shared<DataTypeString>(), VIRTUAL_COLUMN_PART)));
+            read_block.emplace_back(column);
         }
-        // remove input_file_name, input_file_block_start, input_file_block_size due to mergetree doesn't have them
-        input = FileMetaColumns::removeVirtualColumns(input);
+    }
+    return DB::Block(std::move(read_block));
+}
 
-        SparkSQLConfig sql_config = SparkSQLConfig::loadFromContext(context);
-        // case_insensitive_matching
-        if (!sql_config.caseSensitive)
+void MergeTreeRelParser::recoverDeltaNameIfNeeded(
+    DB::QueryPlan & plan, const DB::Block & output, const MergeTreeTableInstance & merge_tree_table)
+{
+    const auto & header = plan.getCurrentHeader();
+    DB::ActionsDAG actions_dag(header.getNamesAndTypesList());
+    NameSet names;
+    bool need_recover = false;
+    for (const auto & column : output)
+    {
+        if (DELTA_META_COLUMN_MAP.contains(column.name))
         {
-            original_input = input;
-            auto all = storage->getInMemoryMetadataPtr()->getColumns().getNamesOfPhysical();
-            std::ranges::for_each(
-                input,
-                [&all](ColumnWithTypeAndName & column)
-                {
-                    const auto found
-                        = std::ranges::find_if(all, [&column](const auto & name) -> bool { return boost::iequals(column.name, name); });
-                    if (found != all.end())
-                        column.name = *found;
-                });
+            need_recover = true;
+            auto tuple = DELTA_META_COLUMN_MAP.at(column.name);
+            ReplaceDeltaNodeFunc func = std::get<2>(tuple);
+            func(actions_dag, merge_tree_table, context);
         }
+
+        names.insert(column.name);
     }
-    else
+
+    if (!need_recover)
+        return;
+
+    actions_dag.removeUnusedActions(names);
+    auto step = std::make_unique<DB::ExpressionStep>(plan.getCurrentHeader(), std::move(actions_dag));
+    step->setStepDescription("Recover virtual columns");
+    steps.emplace_back(step.get());
+    plan.addStep(std::move(step));
+}
+
+void MergeTreeRelParser::replaceNodeWithCaseSensitive(DB::Block & read_block, SparkStorageMergeTreePtr storage)
+{
+    // case_insensitive_matching
+    if (spark_sql_config.caseSensitive)
+        return;
+
+    auto all = storage->getInMemoryMetadataPtr()->getColumns().getNamesOfPhysical();
+    std::ranges::for_each(
+        read_block,
+        [&all](ColumnWithTypeAndName & column)
+        {
+            const auto found
+                = std::ranges::find_if(all, [&column](const auto & name) -> bool { return boost::iequals(column.name, name); });
+            if (found != all.end())
+                column.name = *found;
+        });
+}
+
+
+void MergeTreeRelParser::recoverNodeWithCaseSensitive(DB::QueryPlan & query_plan, const DB::Block & output)
+{
+    if (spark_sql_config.caseSensitive)
+        return;
+
+    auto read_Header = query_plan.getCurrentHeader();
+    NameToNameMap names;
+    names.reserve(output.columns());
+    for (const auto & elem : output.getColumnsWithTypeAndName())
+        names[Poco::toLower(elem.name)] = elem.name;
+
+    DB::NamesWithAliases aliases;
+    aliases.reserve(read_Header.columns());
+    bool need_alisa = false;
+    for (const auto & elem : read_Header)
     {
-        NamesAndTypesList one_column_name_type;
-        one_column_name_type.push_back(storage->getInMemoryMetadataPtr()->getColumns().getAll().front());
-        input = toSampleBlock(one_column_name_type);
-        LOG_DEBUG(getLogger("SerializedPlanParser"), "Try to read ({}) instead of empty header", one_column_name_type.front().dump());
+        if (auto lower_name = Poco::toLower(elem.name); names.contains(lower_name))
+        {
+            if (!need_alisa && !boost::equals(elem.name, names[lower_name]))
+                need_alisa = true;

Review Comment:
   The variable name 'need_alisa' appears to have a spelling mistake; consider renaming it to 'need_alias' for clarity.
   ```suggestion
       bool need_alias = false;
       for (const auto & elem : read_Header)
       {
           if (auto lower_name = Poco::toLower(elem.name); names.contains(lower_name))
           {
               if (!need_alias && !boost::equals(elem.name, names[lower_name]))
                   need_alias = true;
   ```



-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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