-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2057][HUDI-5499] CTAS Generate An External Table When Create Managed Table #6419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9eed30f
f1abf8a
5c1cb21
c945db2
cfd2056
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import org.apache.spark.sql.hudi.HoodieSqlCommonUtils | ||
|
|
||
| val database = "default" | ||
|
|
||
| if (HoodieSqlCommonUtils.isUsingHiveCatalog(spark)) { | ||
| val tableName1 = "test_ctas_1" | ||
| spark.sql( | ||
| s""" | ||
| | create table $tableName1 using hudi | ||
| | tblproperties( | ||
| | primaryKey = 'id' | ||
| | ) | ||
| | AS | ||
| | select 1 as id, 'a1' as name, 10 as price, 1000 as ts | ||
| """.stripMargin) | ||
| if (spark.catalog.getTable(tableName1).tableType.equals("MANAGED")) { | ||
| val tableName2 = "test_ctas_2" | ||
| spark.sql( | ||
| s""" | ||
| | create table $tableName2 using hudi | ||
| | tblproperties( | ||
| | primaryKey = 'id' | ||
| | ) | ||
| | location '/tmp/$tableName2' | ||
| | AS | ||
| | select 1 as id, 'a1' as name, 10 as price, 1000 as ts | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move this to a proper unit test. Bundle validation is not the right place to execute such tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xushiyan Hello, the purpose here is to test the type of the sync hive table, but sync hive cannot be realized in unit test |
||
| """.stripMargin) | ||
| if (spark.catalog.getTable(tableName2).tableType.equals("EXTERNAL")) { | ||
| System.out.println("CTAS hive table type validation passed.") | ||
| System.exit(0) | ||
| } else { | ||
| System.err.println(s"CTAS hive table type validation failed:\n\tThe table type of $database.$tableName2 should be EXTERNAL") | ||
| System.exit(1) | ||
| } | ||
| } else { | ||
| System.err.println(s"CTAS hive table type validation failed:\n\tThe table type of $database.$tableName1 should be MANAGED") | ||
| System.exit(1) | ||
| } | ||
| } else { | ||
| System.err.println(s"CTAS hive table type validation failed:\n\tSpark should us Hive as Session's Catalog") | ||
| System.exit(1) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test that should fail before this fix, to guard any breaking changes in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure out how to implement the test case.Do you have any ideas?