singhpk234 commented on a change in pull request #4401: URL: https://github.com/apache/iceberg/pull/4401#discussion_r835483963
########## File path: spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/procedures/GenerateSymlinkFormatManifestProcedure.java ########## @@ -0,0 +1,142 @@ +/* + * 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.iceberg.spark.procedures; + +import java.util.Arrays; +import org.apache.iceberg.MetadataTableType; +import org.apache.iceberg.Partitioning; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.spark.Spark3Util; +import org.apache.iceberg.spark.SparkTableUtil; +import org.apache.iceberg.spark.source.SparkTable; +import org.apache.iceberg.types.Types; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.catalyst.InternalRow; +import org.apache.spark.sql.connector.catalog.CatalogPlugin; +import org.apache.spark.sql.connector.catalog.TableCatalog; +import org.apache.spark.sql.connector.iceberg.catalog.ProcedureParameter; +import org.apache.spark.sql.types.DataTypes; +import org.apache.spark.sql.types.Metadata; +import org.apache.spark.sql.types.StructField; +import org.apache.spark.sql.types.StructType; + +class GenerateSymlinkFormatManifestProcedure extends BaseProcedure { + private static final ProcedureParameter[] PARAMETERS = new ProcedureParameter[]{ + ProcedureParameter.required("table", DataTypes.StringType), + ProcedureParameter.optional("symlink_root_location", DataTypes.StringType) + }; + + private static final StructType OUTPUT_TYPE = new StructType(new StructField[]{ + new StructField("snapshot_id", DataTypes.LongType, false, Metadata.empty()), + new StructField("data_file_count", DataTypes.LongType, false, Metadata.empty()) + }); + + private static final String PROCEDURE_CONTEXT = "generate symlink format manifest"; + private static final String SYMLINK_DIRECTORY_DEFAULT = "_symlink_format_manifest"; + + private GenerateSymlinkFormatManifestProcedure(TableCatalog tableCatalog) { + super(tableCatalog); + } + + public static SparkProcedures.ProcedureBuilder builder() { + return new Builder<GenerateSymlinkFormatManifestProcedure>() { + @Override + protected GenerateSymlinkFormatManifestProcedure doBuild() { + return new GenerateSymlinkFormatManifestProcedure(tableCatalog()); + } + }; + } + + @Override + public ProcedureParameter[] parameters() { + return PARAMETERS; + } + + @Override + public StructType outputType() { + return OUTPUT_TYPE; + } + + @Override + public InternalRow[] call(InternalRow args) { + String tableIdent = args.getString(0); + Preconditions.checkArgument(tableIdent != null && !tableIdent.isEmpty(), + "Cannot handle an empty identifier for argument table"); + + CatalogPlugin defaultCatalog = spark().sessionState().catalogManager().currentCatalog(); + Spark3Util.CatalogAndIdentifier catalogAndIdent = Spark3Util.catalogAndIdentifier( + PROCEDURE_CONTEXT, spark(), tableIdent, defaultCatalog); + SparkTable sparkTable = loadSparkTable(catalogAndIdent.identifier()); + org.apache.iceberg.Table icebergTable = sparkTable.table(); + ValidationException.check(icebergTable.currentSnapshot() != null, + "Cannot generate symlink manifests for an empty table"); + + long snapshotId = icebergTable.currentSnapshot().snapshotId(); + String symlinkRootLocation = args.isNullAt(1) ? + defaultSymlinkManifestRootLocation(icebergTable.location(), snapshotId) : args.getString(1); + + Types.StructType partitionType = Partitioning.partitionType(icebergTable); + Dataset<Row> entries = SparkTableUtil.loadCatalogMetadataTable(spark(), icebergTable, MetadataTableType.ENTRIES) + .filter("status < 2 AND data_file.content = 0"); + + long rowCount = entries.count(); + if (partitionType.fields().isEmpty()) { + entries.select("data_file.file_path") + .write() + .format("parquet") Review comment: [question] should the format here be "text" instead ? As per this : https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/io/SymlinkTextInputFormat.java#L47-L52 -- 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]
