vinishjail97 commented on code in PR #992: URL: https://github.com/apache/incubator-xtable/pull/992#discussion_r4394757595
########## xtable-spark-extensions/src/main/scala/org/apache/xtable/spark/extensions/XTableIndex.scala: ########## @@ -0,0 +1,103 @@ +/* + * 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.xtable.spark.extensions + +import java.util.{Collections, Properties} + +import org.apache.hadoop.fs.Path +import org.apache.spark.sql.SparkSession + +import org.apache.hudi.common.table.HoodieTableMetaClient + +import org.apache.xtable.conversion.{ + ConversionConfig, + ConversionController, + SourceTable, + TargetTable +} +import org.apache.xtable.hudi.HudiTargetConfig +import org.apache.xtable.hudi.index.HudiBackedSecondaryIndexReader +import org.apache.xtable.iceberg.IcebergConversionSourceProvider +import org.apache.xtable.model.storage.TableFormat +import org.apache.xtable.model.sync.SyncStatusCode + +/** + * The XTable index of an Iceberg table. The index is a Hudi table at the data path of the Iceberg + * table, built and kept current by a sync to a Hudi target with a secondary index on the column of + * the index definition, and read by [[HudiBackedSecondaryIndexReader]]. + */ +case class XTableIndex(spark: SparkSession, sourceTable: SourceTable, definition: IndexDefinition) { Review Comment: Is this tightly coupled to iceberg? The previous PR https://github.com/apache/incubator-xtable/pull/935 removed that limitation right? ########## xtable-spark-extensions/src/test/resources/log4j2.xml: ########## @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. +--> +<Configuration status="warn"> Review Comment: Is this required? ########## xtable-spark-extensions/src/main/scala/org/apache/xtable/spark/extensions/plans/RefreshIndex.scala: ########## @@ -0,0 +1,29 @@ +/* + * 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.xtable.spark.extensions.plans + +import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, UnaryCommand} + +/** {@code REFRESH INDEX name ON table}: syncs an index with the current snapshot of the table. */ Review Comment: I don't think REFRESH INDEX is needed see my comment below. ########## xtable-spark-extensions/src/main/scala/org/apache/xtable/spark/extensions/XTableIndex.scala: ########## @@ -0,0 +1,103 @@ +/* + * 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.xtable.spark.extensions + +import java.util.{Collections, Properties} + +import org.apache.hadoop.fs.Path +import org.apache.spark.sql.SparkSession + +import org.apache.hudi.common.table.HoodieTableMetaClient + +import org.apache.xtable.conversion.{ + ConversionConfig, + ConversionController, + SourceTable, + TargetTable +} +import org.apache.xtable.hudi.HudiTargetConfig +import org.apache.xtable.hudi.index.HudiBackedSecondaryIndexReader +import org.apache.xtable.iceberg.IcebergConversionSourceProvider +import org.apache.xtable.model.storage.TableFormat +import org.apache.xtable.model.sync.SyncStatusCode + +/** + * The XTable index of an Iceberg table. The index is a Hudi table at the data path of the Iceberg + * table, built and kept current by a sync to a Hudi target with a secondary index on the column of + * the index definition, and read by [[HudiBackedSecondaryIndexReader]]. + */ +case class XTableIndex(spark: SparkSession, sourceTable: SourceTable, definition: IndexDefinition) { + + def reader: HudiBackedSecondaryIndexReader = + new HudiBackedSecondaryIndexReader(sourceTable, new IcebergConversionSourceProvider, spark) + + /** Syncs the index with the current snapshot of the table, and builds it if it does not exist. */ + def sync(): Unit = { + val properties = new Properties() + definition.options.foreach { case (key, value) => + properties.setProperty(key, value) + } + properties.setProperty(HudiTargetConfig.HUDI_TABLE_VERSION, "9") + properties.setProperty( + HudiTargetConfig.EXECUTION_ENGINE, + HudiTargetConfig.ExecutionEngine.SPARK.getConfigValue) + properties.setProperty(HudiTargetConfig.SECONDARY_INDEX_COLUMN, definition.column) Review Comment: Do we really need another sync? I think to keep the scope limited, the Spark SQL extensions should use the index if it's current otherwise don't use it and let the user refresh the index by running the sync process using utilities jar, xtable service or spark job. Coupling the sync here with extensions and managing it's correctness requires more checks and the cluster needs to be auto-scaled etc. let's drop this? -- 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]
