Skip to content
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

Temp fix for table name more than 3 parts #923

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,16 @@ class FlintSparkPPLBasicITSuite
val t4Parts = "`spark_catalog`.default.`startTime:1,endTime:2`.`this(is:['a/name'])`"
val t5Parts =
"`spark_catalog`.default.`startTime:1,endTime:2`.`this(is:['sub/name'])`.`this(is:['sub-sub/name'])`"

Seq(t7, t4Parts, t5Parts).foreach { table =>
val ex = intercept[AnalysisException](sql(s"""
| source = $table| head 2
| """.stripMargin))
assert(ex.getMessage().contains("TABLE_OR_VIEW_NOT_FOUND"))
| source = $table| head 2
| """.stripMargin))
// Expected since V2SessionCatalog only supports 3 parts
assert(
ex.getMessage()
.contains(
"[REQUIRES_SINGLE_PART_NAMESPACE] spark_catalog requires a single-part namespace"))
}

Seq(t7, t4Parts, t5Parts).foreach { table =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ public LogicalPlan visitRelation(Relation node, CatalystPlanContext context) {
}
//regular sql algebraic relations
node.getQualifiedNames().forEach(q ->
// Resolving the qualifiedName which is composed of a datasource.schema.table
context.withRelation(new UnresolvedRelation(getTableIdentifier(q).nameParts(), CaseInsensitiveStringMap.empty(), false))
// TODO Do not support 4+ parts table identifier in future (may be reverted this PR in 0.8.0)
// node.getQualifiedNames.getParts().size() > 3
// A Spark TableIdentifier should only contain 3 parts: tableName, databaseName and catalogName.
// If the qualifiedName has more than 3 parts,
// we merge all parts from 3 to last parts into the tableName as one whole
context.withRelation(new UnresolvedRelation(seq(q.getParts()), CaseInsensitiveStringMap.empty(), false))
);
return context.getPlan();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class PPLLogicalPlanBasicQueriesTranslatorTestSuite

test("test read table with backticks and more then 3 parts") {
val context = new CatalystPlanContext
val logPlan =
val logPlan = {
planTransformer.visit(plan(pplParser, "source=`t`.b.`c.d`.`e.f`"), context)
val table = UnresolvedRelation(Seq("t", "b", "c.d.e.f"))
}

val table = UnresolvedRelation(Seq("t", "b", "c.d", "e.f"))
val expectedPlan = Project(Seq(UnresolvedStar(None)), table)
comparePlans(expectedPlan, logPlan, false)
}
Expand Down Expand Up @@ -100,13 +102,14 @@ class PPLLogicalPlanBasicQueriesTranslatorTestSuite
planTransformer.visit(
plan(
pplParser,
"source=`_Basic`.default.`startTime:0,endTime:1`.`logGroups(logGroupIdentifier:['hello/service_log'])`"),
"source=`_Basic`.default.`startTime:0,endTime:1`.`123.logGroups(logGroupIdentifier:['hello.world/service_log'])`"),
context)
val table = UnresolvedRelation(
Seq(
"_Basic",
"default",
"startTime:0,endTime:1.logGroups(logGroupIdentifier:['hello/service_log'])"))
"startTime:0,endTime:1",
"123.logGroups(logGroupIdentifier:['hello.world/service_log'])"))
val expectedPlan = Project(Seq(UnresolvedStar(None)), table)
comparePlans(expectedPlan, logPlan, false)
}
Expand Down
Loading