-
Notifications
You must be signed in to change notification settings - Fork 989
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
[spark] show table extended #4603
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...src/main/scala/org/apache/paimon/spark/catalyst/analysis/PaimonResolvePartitionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.paimon.spark.catalyst.analysis | ||
|
||
import org.apache.spark.sql.PaimonUtils.{normalizePartitionSpec, requireExactMatchedPartitionSpec} | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.analysis.{PartitionSpec, ResolvedPartitionSpec, UnresolvedPartitionSpec} | ||
import org.apache.spark.sql.catalyst.analysis.ResolvePartitionSpec.conf | ||
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
import org.apache.spark.sql.catalyst.expressions.{Cast, Literal} | ||
import org.apache.spark.sql.catalyst.util.CharVarcharUtils | ||
import org.apache.spark.sql.connector.catalog.{Identifier, TableCatalog} | ||
import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Implicits._ | ||
import org.apache.spark.sql.types.{StringType, StructField, StructType} | ||
|
||
object PaimonResolvePartitionSpec { | ||
|
||
def resolve( | ||
catalog: TableCatalog, | ||
tableIndent: Identifier, | ||
partitionSpec: PartitionSpec): ResolvedPartitionSpec = { | ||
val table = catalog.loadTable(tableIndent).asPartitionable | ||
partitionSpec match { | ||
case u: UnresolvedPartitionSpec => | ||
val partitionSchema = table.partitionSchema() | ||
resolvePartitionSpec(table.name(), u, partitionSchema, allowPartitionSpec = false) | ||
case o => o.asInstanceOf[ResolvedPartitionSpec] | ||
} | ||
} | ||
|
||
private def resolvePartitionSpec( | ||
tableName: String, | ||
partSpec: UnresolvedPartitionSpec, | ||
partSchema: StructType, | ||
allowPartitionSpec: Boolean): ResolvedPartitionSpec = { | ||
val normalizedSpec = normalizePartitionSpec(partSpec.spec, partSchema, tableName, conf.resolver) | ||
if (!allowPartitionSpec) { | ||
requireExactMatchedPartitionSpec(tableName, normalizedSpec, partSchema.fieldNames) | ||
} | ||
val partitionNames = normalizedSpec.keySet | ||
val requestedFields = partSchema.filter(field => partitionNames.contains(field.name)) | ||
ResolvedPartitionSpec( | ||
requestedFields.map(_.name), | ||
convertToPartIdent(normalizedSpec, requestedFields), | ||
partSpec.location) | ||
} | ||
|
||
def convertToPartIdent( | ||
partitionSpec: TablePartitionSpec, | ||
schema: Seq[StructField]): InternalRow = { | ||
val partValues = schema.map { | ||
part => | ||
val raw = partitionSpec.get(part.name).orNull | ||
val dt = CharVarcharUtils.replaceCharVarcharWithString(part.dataType) | ||
Cast(Literal.create(raw, StringType), dt, Some(conf.sessionLocalTimeZone)).eval() | ||
} | ||
InternalRow.fromSeq(partValues) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...common/src/main/scala/org/apache/spark/sql/connector/catalog/PaimonCatalogImplicits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.spark.sql.connector.catalog | ||
|
||
object PaimonCatalogImplicits { | ||
|
||
import CatalogV2Implicits._ | ||
|
||
implicit class PaimonCatalogHelper(plugin: CatalogPlugin) extends CatalogHelper(plugin) | ||
|
||
implicit class PaimonNamespaceHelper(namespace: Array[String]) extends NamespaceHelper(namespace) | ||
|
||
// implicit class PaimonTableHelper(table: Table) extends TableHelper(table) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...mmon/src/main/scala/org/apache/paimon/spark/catalyst/analysis/Spark3ResolutionRules.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.paimon.spark.catalyst.analysis | ||
|
||
import org.apache.paimon.spark.commands.{PaimonShowTablePartitionCommand, PaimonShowTablesExtendedCommand} | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.SQLConfHelper | ||
import org.apache.spark.sql.catalyst.analysis.{PartitionSpec, ResolvedNamespace, UnresolvedPartitionSpec} | ||
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, ShowTableExtended} | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.connector.catalog.Identifier | ||
|
||
case class Spark3ResolutionRules(session: SparkSession) | ||
extends Rule[LogicalPlan] | ||
with SQLConfHelper { | ||
|
||
import org.apache.spark.sql.connector.catalog.PaimonCatalogImplicits._ | ||
|
||
override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsDown { | ||
case ShowTableExtended( | ||
ResolvedNamespace(catalog, ns), | ||
pattern, | ||
partitionSpec @ (None | Some(UnresolvedPartitionSpec(_, _))), | ||
output) => | ||
partitionSpec | ||
.map { | ||
spec: PartitionSpec => | ||
val table = Identifier.of(ns.toArray, pattern) | ||
val resolvedSpec = | ||
PaimonResolvePartitionSpec.resolve(catalog.asTableCatalog, table, spec) | ||
PaimonShowTablePartitionCommand(output, catalog.asTableCatalog, table, resolvedSpec) | ||
} | ||
.getOrElse { | ||
PaimonShowTablesExtendedCommand(catalog.asTableCatalog, ns, pattern, output) | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This line can be deleted.