ahmedabu98 commented on code in PR #41249: URL: https://github.com/apache/beam/pull/41249#discussion_r4557641293
########## sdks/java/extensions/sql/delta/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/delta/DeltaChangesTable.java: ########## @@ -0,0 +1,259 @@ +/* + * 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.beam.sdk.extensions.sql.meta.provider.delta; + +import static org.apache.beam.sdk.util.Preconditions.checkStateNotNull; +import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; + +import io.delta.kernel.Snapshot; +import io.delta.kernel.Table; +import io.delta.kernel.defaults.engine.DefaultEngine; +import io.delta.kernel.engine.Engine; +import io.delta.kernel.internal.TableImpl; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.beam.sdk.extensions.sql.meta.ChangeRange; +import org.apache.beam.sdk.extensions.sql.meta.SchemaBaseBeamTable; +import org.apache.beam.sdk.extensions.sql.meta.provider.ManagedOptions; +import org.apache.beam.sdk.io.delta.DeltaCdcReadSchemaTransformProvider; +import org.apache.beam.sdk.io.delta.DeltaIO; +import org.apache.beam.sdk.managed.Managed; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.schemas.Schema.FieldType; +import org.apache.beam.sdk.transforms.Create; +import org.apache.beam.sdk.values.PBegin; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.POutput; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; +import org.apache.hadoop.conf.Configuration; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.joda.time.Instant; + +/** + * The changes of a Delta Lake table, for a {@code CHANGES(...)} call, read from the table's Change + * Data Feed through {@link Managed#DELTA_LAKE_CDC}. Rows carry their change kind as their {@code + * ValueKind}, and the {@code include_metadata_columns} option appends the metadata columns {@code + * _change_type}, {@code _commit_version} and {@code _commit_timestamp}. {@code _change_type} holds + * the change types of Delta Lake: {@code insert}, {@code update_preimage}, {@code update_postimage} + * and {@code delete}. + * + * <p>A Delta Lake table only records its changes from the version that enabled Change Data Feed on + * it, so the range needs a start. When the pipeline is built, the range is resolved to the versions + * it holds, and the read is pinned to them: changes committed later are not read. A version bound + * must name a version that exists. A timestamp range that holds no versions reads no rows. + */ +class DeltaChangesTable extends SchemaBaseBeamTable { + private static final Schema READ_CONFIG_SCHEMA = + new DeltaCdcReadSchemaTransformProvider().configurationSchema(); + private static final String INCLUDE_METADATA_COLUMNS = "include_metadata_columns"; + private static final String START_VERSION = "start_version"; + private static final String END_VERSION = "end_version"; + + /** The metadata columns of the Change Data Feed, in the order they follow the table's columns. */ + @VisibleForTesting + static final List<String> METADATA_COLUMNS = + ImmutableList.of( + DeltaIO.CHANGE_TYPE_COLUMN, + DeltaIO.COMMIT_VERSION_COLUMN, + DeltaIO.COMMIT_TIMESTAMP_COLUMN); Review Comment: nit: I think this belongs inside DeltaIO -- 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]
