Skip to content

Commit

Permalink
[branch-2.0](multi catalog) Print serde properties when show create h…
Browse files Browse the repository at this point in the history
…ive-external-table (apache#34967)
  • Loading branch information
xy720 authored and weixingyu12 committed May 21, 2024
1 parent d82407f commit 0d918af
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@ public static String showCreateTable(org.apache.hadoop.hive.metastore.api.Table
output.append("ROW FORMAT SERDE\n")
.append(String.format(" '%s'\n", descriptor.getSerdeInfo().getSerializationLib()));
}
if (descriptor.getSerdeInfo().isSetParameters()) {
output.append("WITH SERDEPROPERTIES (\n")
.append(descriptor.getSerdeInfo().getParameters().entrySet().stream()
.map(entry -> String.format(" '%s' = '%s'", entry.getKey(), entry.getValue()))
.collect(Collectors.joining(",\n")))
.append(")\n");
}
if (descriptor.isSetInputFormat()) {
output.append("STORED AS INPUTFORMAT\n")
.append(String.format(" '%s'\n", descriptor.getInputFormat()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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_hive_show_create_table", "p0,external,hive,external_docker,external_docker_hive") {
String enabled = context.config.otherConfigs.get("enableHiveTest")
if (enabled != null && enabled.equalsIgnoreCase("true")) {
String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
String hms_port = context.config.otherConfigs.get("hms_port")
String hdfs_port = context.config.otherConfigs.get("hms_port")
String catalog_name = "test_hive_show_create_table"
String table_name = "table_with_pars";

sql """drop catalog if exists ${catalog_name};"""

sql """
create catalog if not exists ${catalog_name} properties (
'type'='hms',
'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hms_port}',
'fs.defaultFS' = 'hdfs://${externalEnvIp}:${hdfs_port}'
);
"""
logger.info("catalog " + catalog_name + " created")
sql """switch ${catalog_name};"""
logger.info("switched to catalog " + catalog_name)
sql """use `default`;"""

def serde = "'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'"
def serdeFormat = "'serialization.format' = '|'"
def filedDelim = "'field.delim' = '|'"
def inputFormat = "'org.apache.hadoop.mapred.TextInputFormat'"
def outputFormat = "'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'"
def create_tbl_res = sql """ show create table table_with_pars """
logger.info("${create_tbl_res}")
assertTrue(create_tbl_res.toString().containsIgnoreCase("${serde}"))
assertTrue(create_tbl_res.toString().containsIgnoreCase("${serdeFormat}"))
assertTrue(create_tbl_res.toString().containsIgnoreCase("${filedDelim}"))
assertTrue(create_tbl_res.toString().containsIgnoreCase("${inputFormat}"))
assertTrue(create_tbl_res.toString().containsIgnoreCase("${outputFormat}"))
}
}

0 comments on commit 0d918af

Please sign in to comment.