c21 commented on a change in pull request #34497:
URL: https://github.com/apache/spark/pull/34497#discussion_r744186904
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -1250,7 +1252,38 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with
SQLConfHelper with Logg
*/
override def visitTableName(ctx: TableNameContext): LogicalPlan =
withOrigin(ctx) {
val tableId = visitMultipartIdentifier(ctx.multipartIdentifier)
- val table = mayApplyAliasPlan(ctx.tableAlias, UnresolvedRelation(tableId))
+ val properties = new util.HashMap[String, String]
+ if (ctx.asOf != null && ctx.asOf.version != null) {
+ properties.put(TableCatalog.PROP_VERSION, ctx.asOf.version.getText)
Review comment:
Should we also check `version` to be a non-negative `int`/`long`? (I
guess `int` should be enough).
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
##########
@@ -2430,4 +2435,34 @@ class DDLParserSuite extends AnalysisTest {
comparePlans(parsePlan(timestampTypeSql), insertPartitionPlan(timestamp))
comparePlans(parsePlan(binaryTypeSql), insertPartitionPlan(binaryStr))
}
+
+ test("as of syntax") {
+ var properties = new util.HashMap[String, String]
+ properties.put(TableCatalog.PROP_VERSION, "123456789")
+ comparePlans(
+ parsePlan("SELECT * FROM a.b.c VERSION AS OF 123456789"),
Review comment:
shall we also test a bad `version` number?
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala
##########
@@ -285,6 +285,26 @@ private[sql] object CatalogV2Util {
case _: NoSuchNamespaceException => None
}
+ def loadTable(
Review comment:
wondering why we do not choose to modify existing `loadTable(catalog:
CatalogPlugin, ident: Identifier)` above?
##########
File path:
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java
##########
@@ -94,6 +104,36 @@
*/
Table loadTable(Identifier ident) throws NoSuchTableException;
+ /**
+ * Load table metadata by {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and
not a table, this
+ * must throw {@link NoSuchTableException}.
+ *
+ * @param ident a table identifier
+ * @param version version of the table
+ * @return the table's metadata
+ * @throws NoSuchTableException If the table doesn't exist or is a view
+ */
+ default Table loadTable(Identifier ident, String version) throws
NoSuchTableException {
Review comment:
should we define the `version` parameter type as `int`?
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -1250,7 +1252,38 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with
SQLConfHelper with Logg
*/
override def visitTableName(ctx: TableNameContext): LogicalPlan =
withOrigin(ctx) {
val tableId = visitMultipartIdentifier(ctx.multipartIdentifier)
- val table = mayApplyAliasPlan(ctx.tableAlias, UnresolvedRelation(tableId))
+ val properties = new util.HashMap[String, String]
+ if (ctx.asOf != null && ctx.asOf.version != null) {
+ properties.put(TableCatalog.PROP_VERSION, ctx.asOf.version.getText)
+ } else if (ctx.asOf != null && ctx.asOf.TIMESTAMP != null) {
+ val ts = ctx.asOf.timestamp.getText
+ if (ts.length == "'yyyy-MM-dd'".length) {
+ val df = DateFormatter()
+ try {
+ properties.put(
+ TableCatalog.PROP_TIMESTAMP,
+ df.parse(ts.substring(1, ts.length - 1)).toString)
+ } catch {
+ case _: Throwable =>
+ throw new IllegalArgumentException(s"Illegal timestamp value $ts
in TIMESTAMP AS OF")
Review comment:
Should we also include original `Throwable` inside the new
`IllegalArgumentException`? It might help debug.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]