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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3ae6b4ad587 [bugfix](hive)Use the connected user to initialize the 
owner of the hive table (#41876)
3ae6b4ad587 is described below

commit 3ae6b4ad587d8bc3c803179f334bc40f1bceea37
Author: wuwenchi <wuwenchi...@hotmail.com>
AuthorDate: Fri Oct 18 15:01:13 2024 +0800

    [bugfix](hive)Use the connected user to initialize the owner of the hive 
table (#41876)
    
    Use the connected user to initialize the owner of the hive table created
    by Doris.
    If user specified `"owner"` property in create table statement, will use
    user specified owner.
    
    ```
    mysql> create table test_table(k1 int) properties("owner" = "user2");
    
    mysql> show create table test_table;
    CREATE TABLE `test_table`(
      `k1` int COMMENT '')
    COMMENT ''
    ROW FORMAT SERDE
      'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
    WITH SERDEPROPERTIES (
    )
    STORED AS INPUTFORMAT
      'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
    OUTPUTFORMAT
      'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
    LOCATION
      'hdfs://172.20.32.136:8020/user/hive/warehouse/test.db/test_table'
    TBLPROPERTIES (
      'owner'='user2',
      'transient_lastDdlTime'='1729162217',
      'orc.compress'='zlib',
      'doris.version'='doris-0.0.0--de4e2eadc3')
    ```
    
    ---------
    
    Co-authored-by: morningman <morning...@163.com>
---
 .../org/apache/doris/datasource/hive/HiveMetadataOps.java     |  7 +++++++
 .../java/org/apache/doris/datasource/hive/HmsCommitTest.java  | 11 +++++++++--
 .../suites/external_table_p0/hive/ddl/test_hive_ddl.groovy    |  5 ++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
index 022f646343d..a660cb148ac 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
@@ -40,6 +40,7 @@ import org.apache.doris.datasource.jdbc.client.JdbcClient;
 import org.apache.doris.datasource.jdbc.client.JdbcClientConfig;
 import org.apache.doris.datasource.operations.ExternalMetadataOps;
 import org.apache.doris.datasource.property.constants.HMSProperties;
+import org.apache.doris.qe.ConnectContext;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
@@ -172,6 +173,12 @@ public class HiveMetadataOps implements 
ExternalMetadataOps {
         }
         try {
             Map<String, String> props = stmt.getProperties();
+            // set default owner
+            if (!props.containsKey("owner")) {
+                if (ConnectContext.get() != null) {
+                    props.put("owner", 
ConnectContext.get().getUserIdentity().getUser());
+                }
+            }
             String fileFormat = props.getOrDefault(FILE_FORMAT_KEY, 
Config.hive_default_file_format);
             Map<String, String> ddlProps = new HashMap<>();
             for (Map.Entry<String, String> entry : props.entrySet()) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HmsCommitTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HmsCommitTest.java
index 395a063fbc8..0e79f8ee2b5 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HmsCommitTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HmsCommitTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.datasource.hive;
 
+import org.apache.doris.analysis.UserIdentity;
 import org.apache.doris.backup.Status;
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.PrimitiveType;
@@ -35,6 +36,7 @@ import org.apache.doris.thrift.TUniqueId;
 import org.apache.doris.thrift.TUpdateMode;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import mockit.Mock;
 import mockit.MockUp;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -54,6 +56,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Random;
 import java.util.UUID;
@@ -127,7 +130,7 @@ public class HmsCommitTest {
     }
 
     @Before
-    public void before() {
+    public void before() throws IOException {
         // create table for tbWithPartition
         List<Column> columns = new ArrayList<>();
         columns.add(new Column("c1", PrimitiveType.INT, true));
@@ -136,11 +139,15 @@ public class HmsCommitTest {
         List<String> partitionKeys = new ArrayList<>();
         partitionKeys.add("c3");
         String fileFormat = "orc";
+        Map<String, String> tblProperties = Maps.newHashMap();
+        tblProperties.put("owner", "admin");
         HiveTableMetadata tableMetadata = new HiveTableMetadata(
                 dbName, tbWithPartition, Optional.of(dbLocation + 
tbWithPartition + UUID.randomUUID()),
                 columns, partitionKeys,
-                new HashMap<>(), fileFormat, "");
+                tblProperties, fileFormat, "");
         hmsClient.createTable(tableMetadata, true);
+        Table tbl = hmsClient.getTable(dbName, tbWithPartition);
+        Assert.assertEquals(UserIdentity.ADMIN.getUser(), 
tbl.getParameters().get("owner"));
 
         // create table for tbWithoutPartition
         HiveTableMetadata tableMetadata2 = new HiveTableMetadata(
diff --git 
a/regression-test/suites/external_table_p0/hive/ddl/test_hive_ddl.groovy 
b/regression-test/suites/external_table_p0/hive/ddl/test_hive_ddl.groovy
index 4bacc7578ef..626f6b2bfbf 100644
--- a/regression-test/suites/external_table_p0/hive/ddl/test_hive_ddl.groovy
+++ b/regression-test/suites/external_table_p0/hive/ddl/test_hive_ddl.groovy
@@ -273,6 +273,7 @@ suite("test_hive_ddl", 
"p0,external,hive,external_docker,external_docker_hive")
             def create_tbl_res = sql """ show create table 
loc_tbl_${file_format}_default """
             logger.info("${create_tbl_res}")
             
assertTrue(create_tbl_res.toString().containsIgnoreCase("${loc}/loc_tbl_${file_format}_default"))
+            
assertTrue(create_tbl_res.toString().containsIgnoreCase("'owner'='root'"))
 
             sql """ INSERT INTO loc_tbl_${file_format}_default values(1)  """
 
@@ -303,12 +304,14 @@ suite("test_hive_ddl", 
"p0,external,hive,external_docker,external_docker_hive")
                     )  ENGINE=hive 
                     PROPERTIES (
                       'file_format'='${file_format}',
-                      'location'='${tbl_loc}'
+                      'location'='${tbl_loc}',
+                      'owner' = 'doris_writer'
                     )
                  """
             def create_tbl_res2 = sql """ show create table 
loc_tbl_${file_format}_custom """
             logger.info("${create_tbl_res2}")
             
assertTrue(create_tbl_res2.toString().containsIgnoreCase("${tbl_loc}"))
+            
assertTrue(create_tbl_res2.toString().containsIgnoreCase("'owner'='doris_writer'"))
             sql """ INSERT INTO loc_tbl_${file_format}_custom values(1)  """
             def tvfRes2 = sql """ SELECT * FROM hdfs(
                                     'uri'='${tbl_loc}/*',


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

Reply via email to