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: [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]

Reply via email to