You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/07/15 01:54:12 UTC

[GitHub] [iceberg] hililiwei opened a new pull request, #5281: Spark: Spark SQL Extensions for tag

hililiwei opened a new pull request, #5281:
URL: https://github.com/apache/iceberg/pull/5281

   Co-authored-by: liliwei [liliwei14@huawei.com](mailto:liliwei14@huawei.com)
   Co-authored-by: xuwei [xuwei132@huawei.com](mailto:xuwei132@huawei.com)
   Co-authored-by: chidayong [chidayong2@h-partners.com](mailto:chidayong2@h-partners.com)
   
   base on https://github.com/apache/iceberg/pull/5209#issuecomment-1184719859
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r926357330


##########
spark/v3.3/spark-extensions/src/main/antlr/org.apache.spark.sql.catalyst.parser.extensions/IcebergSqlExtensions.g4:
##########
@@ -73,6 +73,10 @@ statement
     | ALTER TABLE multipartIdentifier WRITE writeSpec                                       #setWriteDistributionAndOrdering
     | ALTER TABLE multipartIdentifier SET IDENTIFIER_KW FIELDS fieldList                    #setIdentifierFields
     | ALTER TABLE multipartIdentifier DROP IDENTIFIER_KW FIELDS fieldList                   #dropIdentifierFields
+    | ALTER TABLE multipartIdentifier CREATE TAG identifier (AS OF VERSION snapshotId)?  (RETAIN FOR snapshotRefRetain snapshotRefRetainTimeUnit)? #createTag
+    | ALTER TABLE multipartIdentifier REPLACE TAG identifier (AS OF VERSION snapshotId)?  (RETAIN FOR snapshotRefRetain snapshotRefRetainTimeUnit)? #replaceTag
+    | ALTER TABLE multipartIdentifier DROP TAG identifier #removeTag
+    | ALTER TABLE multipartIdentifier ALTER TAG identifier RETAIN snapshotRefRetain snapshotRefRetainTimeUnit #alterTagRetention

Review Comment:
   RETAIN FOR instead of just Retain? 



##########
spark/v3.3/spark-extensions/src/main/antlr/org.apache.spark.sql.catalyst.parser.extensions/IcebergSqlExtensions.g4:
##########
@@ -73,6 +73,10 @@ statement
     | ALTER TABLE multipartIdentifier WRITE writeSpec                                       #setWriteDistributionAndOrdering
     | ALTER TABLE multipartIdentifier SET IDENTIFIER_KW FIELDS fieldList                    #setIdentifierFields
     | ALTER TABLE multipartIdentifier DROP IDENTIFIER_KW FIELDS fieldList                   #dropIdentifierFields
+    | ALTER TABLE multipartIdentifier CREATE TAG identifier (AS OF VERSION snapshotId)?  (RETAIN FOR snapshotRefRetain snapshotRefRetainTimeUnit)? #createTag
+    | ALTER TABLE multipartIdentifier REPLACE TAG identifier (AS OF VERSION snapshotId)?  (RETAIN FOR snapshotRefRetain snapshotRefRetainTimeUnit)? #replaceTag
+    | ALTER TABLE multipartIdentifier DROP TAG identifier #removeTag
+    | ALTER TABLE multipartIdentifier ALTER TAG identifier RETAIN snapshotRefRetain snapshotRefRetainTimeUnit #alterTagRetention

Review Comment:
   For consistency, RETAIN FOR instead of just Retain? 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1193622353

   Thanks for review, addressed the round of comments
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1305316234

   > 
   
   That's a good question.
   @amogh-jahagirdar @jackye1995 @rdblue What do you think? Should we continue to create syntax, or switch to something like CALL?
   
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1208195889

   Auto-formatted and added `IF EXISTS`.
   Could you please help to take a look when you are avaliable? @amogh-jahagirdar
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r927413415


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ReplaceTagExec.scala:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.ReplaceTag
+import org.apache.spark.sql.connector.catalog._
+
+case class ReplaceTagExec(
+                           catalog: TableCatalog,
+                           ident: Identifier,
+                           replaceTag: ReplaceTag) extends LeafV2CommandExec {
+
+  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+  override lazy val output: Seq[Attribute] = Nil
+
+  override protected def run(): Seq[InternalRow] = {
+    catalog.loadTable(ident) match {
+      case iceberg: SparkTable =>
+
+        val snapshotId = replaceTag.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId())
+        val manageSnapshots = iceberg.table.manageSnapshots()
+        if (replaceTag.snapshotId.nonEmpty) {
+          manageSnapshots.replaceTag(replaceTag.tag, snapshotId)
+        }
+        if (replaceTag.snapshotRefRetain.nonEmpty) {
+          manageSnapshots
+            .setMaxRefAgeMs(replaceTag.tag, replaceTag.snapshotRefRetain.getOrElse(5 * 24 * 60 * 60 * 1000L))
+        }

Review Comment:
   make sence



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1277161614

   Could you please take a look when you are avaliable? cc @amogh-jahagirdar @jackye1995 @rdblue
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r927520624


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:
##########
@@ -79,6 +84,51 @@ class IcebergSqlExtensionsAstBuilder(delegate: ParserInterface) extends IcebergS
       Option(ctx.name).map(_.getText))
   }
 
+  /**
+   * Create an CREATE TAG logical command.
+   */
+  override def visitCreateTag(ctx: CreateTagContext): CreateTag =  withOrigin(ctx) {
+    CreateTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REPLACE TAG logical command.
+   */
+  override def visitReplaceTag(ctx: ReplaceTagContext): ReplaceTag =  withOrigin(ctx) {
+    ReplaceTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REMOVE TAG logical command.
+   */
+  override def visitRemoveTag(ctx: RemoveTagContext): RemoveTag = withOrigin(ctx) {
+    RemoveTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText
+    )
+  }
+
+  /**
+   * Create an ALTER TAG RETENTION logical command.
+   */
+  override def visitAlterTagRetention(ctx: AlterTagRetentionContext): AlterTagRefRetention =  withOrigin(ctx) {
+    AlterTagRefRetention(
+      typedVisit[Seq[String]](ctx.multipartIdentifier()),

Review Comment:
   I caused it to pass when I used a space to create branch.
   
   



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r927520075


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:
##########
@@ -79,6 +84,51 @@ class IcebergSqlExtensionsAstBuilder(delegate: ParserInterface) extends IcebergS
       Option(ctx.name).map(_.getText))
   }
 
+  /**
+   * Create an CREATE TAG logical command.
+   */
+  override def visitCreateTag(ctx: CreateTagContext): CreateTag =  withOrigin(ctx) {
+    CreateTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REPLACE TAG logical command.
+   */
+  override def visitReplaceTag(ctx: ReplaceTagContext): ReplaceTag =  withOrigin(ctx) {
+    ReplaceTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REMOVE TAG logical command.
+   */
+  override def visitRemoveTag(ctx: RemoveTagContext): RemoveTag = withOrigin(ctx) {
+    RemoveTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText
+    )
+  }
+
+  /**
+   * Create an ALTER TAG RETENTION logical command.
+   */
+  override def visitAlterTagRetention(ctx: AlterTagRetentionContext): AlterTagRefRetention =  withOrigin(ctx) {
+    AlterTagRefRetention(
+      typedVisit[Seq[String]](ctx.multipartIdentifier()),

Review Comment:
   added.
   I find that we only checks whether the branch\tag name is `null` in `UpdateSnapshotReferencesOperation`, but does not check `empty`. Should we add it. If need be, I can raise a PR.



##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:
##########
@@ -79,6 +84,51 @@ class IcebergSqlExtensionsAstBuilder(delegate: ParserInterface) extends IcebergS
       Option(ctx.name).map(_.getText))
   }
 
+  /**
+   * Create an CREATE TAG logical command.
+   */
+  override def visitCreateTag(ctx: CreateTagContext): CreateTag =  withOrigin(ctx) {
+    CreateTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REPLACE TAG logical command.
+   */
+  override def visitReplaceTag(ctx: ReplaceTagContext): ReplaceTag =  withOrigin(ctx) {
+    ReplaceTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REMOVE TAG logical command.
+   */
+  override def visitRemoveTag(ctx: RemoveTagContext): RemoveTag = withOrigin(ctx) {
+    RemoveTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText
+    )
+  }
+
+  /**
+   * Create an ALTER TAG RETENTION logical command.
+   */
+  override def visitAlterTagRetention(ctx: AlterTagRetentionContext): AlterTagRefRetention =  withOrigin(ctx) {
+    AlterTagRefRetention(
+      typedVisit[Seq[String]](ctx.multipartIdentifier()),

Review Comment:
   added.
   I find that we only checks whether the branch\tag name is `null` in `UpdateSnapshotReferencesOperation`, but does not check `empty`. Should we add it? If need be, I can raise a PR.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei closed pull request #5281: Spark: Spark SQL Extensions for tag

Posted by "hililiwei (via GitHub)" <gi...@apache.org>.
hililiwei closed pull request #5281: Spark: Spark SQL Extensions for tag
URL: https://github.com/apache/iceberg/pull/5281


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1221193797

   Could you please take a look when you are avaliable? cc @amogh-jahagirdar @jackye1995  @rdblue 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r926216175


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateTagExec.scala:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.CreateTag
+import org.apache.spark.sql.connector.catalog._
+
+case class CreateTagExec(
+                             catalog: TableCatalog,
+                             ident: Identifier,
+                             createTag: CreateTag) extends LeafV2CommandExec {
+
+  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+  override lazy val output: Seq[Attribute] = Nil
+
+  override protected def run(): Seq[InternalRow] = {
+    catalog.loadTable(ident) match {
+      case iceberg: SparkTable =>
+
+        val snapshotId = createTag.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId())
+        iceberg.table.manageSnapshots()
+          .createTag(createTag.tag, snapshotId)
+          .setMaxRefAgeMs(createTag.tag, createTag.snapshotRefRetain.getOrElse(5 * 24 * 60 * 60 * 1000L))

Review Comment:
   I don't think we should default to 5 days for the ref age. I think by default, the max ref age should not be set and by default be retained forever.



##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:
##########
@@ -79,6 +84,51 @@ class IcebergSqlExtensionsAstBuilder(delegate: ParserInterface) extends IcebergS
       Option(ctx.name).map(_.getText))
   }
 
+  /**
+   * Create an CREATE TAG logical command.
+   */
+  override def visitCreateTag(ctx: CreateTagContext): CreateTag =  withOrigin(ctx) {
+    CreateTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REPLACE TAG logical command.
+   */
+  override def visitReplaceTag(ctx: ReplaceTagContext): ReplaceTag =  withOrigin(ctx) {
+    ReplaceTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REMOVE TAG logical command.
+   */
+  override def visitRemoveTag(ctx: RemoveTagContext): RemoveTag = withOrigin(ctx) {
+    RemoveTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText
+    )
+  }
+
+  /**
+   * Create an ALTER TAG RETENTION logical command.
+   */
+  override def visitAlterTagRetention(ctx: AlterTagRetentionContext): AlterTagRefRetention =  withOrigin(ctx) {
+    AlterTagRefRetention(
+      typedVisit[Seq[String]](ctx.multipartIdentifier()),

Review Comment:
   High level question: Don't we need more validation here in the AstBuilder (i.e. tag is not empty, snapshot id is not negative). These would fail later on anyways but it seems better to fail faster here



##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ReplaceTagExec.scala:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.ReplaceTag
+import org.apache.spark.sql.connector.catalog._
+
+case class ReplaceTagExec(
+                           catalog: TableCatalog,
+                           ident: Identifier,
+                           replaceTag: ReplaceTag) extends LeafV2CommandExec {
+
+  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+  override lazy val output: Seq[Attribute] = Nil
+
+  override protected def run(): Seq[InternalRow] = {
+    catalog.loadTable(ident) match {
+      case iceberg: SparkTable =>
+
+        val snapshotId = replaceTag.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId())
+        val manageSnapshots = iceberg.table.manageSnapshots()
+        if (replaceTag.snapshotId.nonEmpty) {
+          manageSnapshots.replaceTag(replaceTag.tag, snapshotId)
+        }
+        if (replaceTag.snapshotRefRetain.nonEmpty) {
+          manageSnapshots
+            .setMaxRefAgeMs(replaceTag.tag, replaceTag.snapshotRefRetain.getOrElse(5 * 24 * 60 * 60 * 1000L))
+        }

Review Comment:
   Same, I don't think when replacing there should be a default ref retention of 5 days. I think we should retain refs forever by default. Let me know what you think! 



##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ReplaceTagExec.scala:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.ReplaceTag
+import org.apache.spark.sql.connector.catalog._
+
+case class ReplaceTagExec(
+                           catalog: TableCatalog,
+                           ident: Identifier,
+                           replaceTag: ReplaceTag) extends LeafV2CommandExec {
+

Review Comment:
   Indentation



##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/RemoveTagExec.scala:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.RemoveTag
+import org.apache.spark.sql.connector.catalog._
+
+case class RemoveTagExec(
+                          catalog: TableCatalog,
+                          ident: Identifier,
+                          removeTag: RemoveTag) extends LeafV2CommandExec {

Review Comment:
   Same indentation



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1204998527

   `
   ALTER TABLE table DROP  TAG reference
   `
   How about add ` IF EXIST` key?
   `
   ALTER TABLE table DROP TAG {IF EXIST} reference
   `
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r927413193


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateTagExec.scala:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.spark.source.SparkTable
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.CreateTag
+import org.apache.spark.sql.connector.catalog._
+
+case class CreateTagExec(
+                             catalog: TableCatalog,
+                             ident: Identifier,
+                             createTag: CreateTag) extends LeafV2CommandExec {
+
+  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+  override lazy val output: Seq[Attribute] = Nil
+
+  override protected def run(): Seq[InternalRow] = {
+    catalog.loadTable(ident) match {
+      case iceberg: SparkTable =>
+
+        val snapshotId = createTag.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId())
+        iceberg.table.manageSnapshots()
+          .createTag(createTag.tag, snapshotId)
+          .setMaxRefAgeMs(createTag.tag, createTag.snapshotRefRetain.getOrElse(5 * 24 * 60 * 60 * 1000L))

Review Comment:
   Let's set it to long.max so it doesn't expire.
   
   



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] hililiwei commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
hililiwei commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r927520624


##########
spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:
##########
@@ -79,6 +84,51 @@ class IcebergSqlExtensionsAstBuilder(delegate: ParserInterface) extends IcebergS
       Option(ctx.name).map(_.getText))
   }
 
+  /**
+   * Create an CREATE TAG logical command.
+   */
+  override def visitCreateTag(ctx: CreateTagContext): CreateTag =  withOrigin(ctx) {
+    CreateTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REPLACE TAG logical command.
+   */
+  override def visitReplaceTag(ctx: ReplaceTagContext): ReplaceTag =  withOrigin(ctx) {
+    ReplaceTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText,
+      Option(ctx.snapshotId()).map(_.getText.toLong),
+      Option(ctx.snapshotRefRetain()).map(_.getText.toLong * timeUnit(ctx.snapshotRefRetainTimeUnit().getText))
+    )
+  }
+
+  /**
+   * Create an REMOVE TAG logical command.
+   */
+  override def visitRemoveTag(ctx: RemoveTagContext): RemoveTag = withOrigin(ctx) {
+    RemoveTag(
+      typedVisit[Seq[String]](ctx.multipartIdentifier),
+      ctx.identifier().getText
+    )
+  }
+
+  /**
+   * Create an ALTER TAG RETENTION logical command.
+   */
+  override def visitAlterTagRetention(ctx: AlterTagRetentionContext): AlterTagRefRetention =  withOrigin(ctx) {
+    AlterTagRefRetention(
+      typedVisit[Seq[String]](ctx.multipartIdentifier()),

Review Comment:
   I caused it to pass when I used a space to create branch.
   
   



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#discussion_r926352699


##########
spark/v3.3/spark-extensions/src/main/antlr/org.apache.spark.sql.catalyst.parser.extensions/IcebergSqlExtensions.g4:
##########
@@ -164,18 +168,31 @@ fieldList
     ;
 
 nonReserved
-    : ADD | ALTER | AS | ASC | BY | CALL | DESC | DROP | FIELD | FIRST | LAST | NULLS | ORDERED | PARTITION | TABLE | WRITE
-    | DISTRIBUTED | LOCALLY | UNORDERED | REPLACE | WITH | IDENTIFIER_KW | FIELDS | SET
-    | TRUE | FALSE
+    : ADD | ALTER | AS | ASC | BY | CALL | CREATE |  DESC | DROP | FIELD | FIRST | LAST | NULLS | OF | ORDERED

Review Comment:
   I'm not sure about adding CREATE as a non reserved keyword. 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] zinking commented on pull request #5281: Spark: Spark SQL Extensions for tag

Posted by GitBox <gi...@apache.org>.
zinking commented on PR #5281:
URL: https://github.com/apache/iceberg/pull/5281#issuecomment-1282324409

   I think we should refrain ourselves from creating new syntaxes unless this syntax has been standardized. 
   
   for example, why not use `CALL` store procedure here? it's less work and more eco friendly.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org