sunke38 opened a new issue, #5693:
URL: https://github.com/apache/hudi/issues/5693
**Describe the problem you faced**
I use spark sql to create table and sync to hive and query by presto. My
code get table schema from json and create table if its not exists. Here is my
problem, even I set hoodie.datasource.hive_sync.database in sql, the new table
is put under default database instead of I set.
**code**
```
private def chackAndCreateTable(row: Row)(implicit sparkSession:
SparkSession): Unit = {
try{
var chackTableExist = s"SHOW CREATE TABLE ${row.getAs("table")}_cow"
sparkSession.sql(chackTableExist)
}catch{
case ex:AnalysisException => {
if(ex.message.contains("Table or permanent view not found")){
println(s"todo 没有找到${row.getAs("table")}_cow表 自动建 ods表")
sparkSession.sql(s"""create schema if not exists
${row.getAs("database")} location
'/hudi/datalake/${row.getAs("database")}/';""");
//println(row.schema.toDDL)
var sqlString = s"""create table ${row.getAs("table")}_cow
(${row.schema.toDDL})
|using hudi tblproperties (
|type = 'cow',
|primaryKey = 'pk',
|preCombineField = 'es',
|hoodie.datasource.hive_sync.enable = true,
|hoodie.datasource.hive_sync.database=
'${row.getAs("database")}',
|hoodie.datasource.hive_sync.table = '${row.getAs("table")}_cow',
|hive_sync.metastore.uris = 'thrift://****:9083',
|hive_sync.jdbc_url= 'jdbc:hive2://****:10000',
|hoodie.datasource.hive_sync.mode = 'hms'
|) location
'/hudi/datalake/${row.getAs("database")}/${row.getAs("table")}_cow';
""".stripMargin.stripMargin('\n')
val tbDf = sparkSession.sql(sqlString).printSchema()
println(sqlString)
```
**Expected behavior**
create table and sync to hive. that table should be under the schema I set
Environment Description
Hudi version : 0.11
Spark version : 3.2.1
Hadoop version : 3.2.2
Storage (HDFS/S3/GCS..) : HDFS
Running on Docker? (yes/no) : no
Stacktrace
N/A but here is my output from code
```
22/05/26 09:14:27 WARN HiveConf: HiveConf of name
hive.metastore.event.db.notification.api.auth does not exist
22/05/26 09:14:27 WARN SessionState: METASTORE_FILTER_HOOK will be ignored,
since hive.security.authorization.manager is set to instance of
HiveAuthorizerFactory.
root
create table bko_****_cow (`login_id` ,`es` TIMESTAMP,`database` STRING,`pk`
STRING,`table` STRING)
using hudi tblproperties (
type = 'cow',
primaryKey = 'pk',
preCombineField = 'es',
hoodie.datasource.hive_sync.enable = true,
hoodie.datasource.hive_sync.database= 'dev_****',
hoodie.datasource.hive_sync.table = 'bko_****_cow',
hive_sync.metastore.uris = 'thrift://****:9083',
hive_sync.jdbc_url= 'jdbc:hive2://****:10000',
hoodie.datasource.hive_sync.mode = 'hms'
) location '/hudi/datalake/dev_cardiot_platform/bko_user_login_log_cow';
```
**Stacktrace**
```Add the stacktrace of the error.```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]