-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Added IcebergArrowInputSourceReader #19510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
823018b
a873c4d
c420836
866a093
2339330
8447ce0
f151f5b
87bdc7f
c774363
6db57a7
a7fa10c
113948f
6a3ad85
ed6c2ff
498daa6
484ebea
bcbfe67
2dedaa9
2111b0a
bf71afb
3fbb73f
2845d46
d046573
197afce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * 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.druid.iceberg.input; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Preconditions; | ||
| import org.apache.druid.common.config.Configs; | ||
| import org.apache.druid.iceberg.filter.IcebergFilter; | ||
| import org.apache.iceberg.Table; | ||
| import org.joda.time.DateTime; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| public abstract class AbstractIcebergInputSource | ||
| { | ||
| protected final String tableName; | ||
| protected final String namespace; | ||
| protected final IcebergCatalog icebergCatalog; | ||
| protected final IcebergFilter icebergFilter; | ||
| protected final DateTime snapshotTime; | ||
| protected final ResidualFilterMode residualFilterMode; | ||
|
|
||
| protected AbstractIcebergInputSource( | ||
| final String tableName, | ||
| final String namespace, | ||
| @Nullable final IcebergFilter icebergFilter, | ||
| final IcebergCatalog icebergCatalog, | ||
| @Nullable final DateTime snapshotTime, | ||
| @Nullable final ResidualFilterMode residualFilterMode | ||
| ) | ||
| { | ||
| this.tableName = Preconditions.checkNotNull(tableName, "tableName cannot be null"); | ||
| this.namespace = Preconditions.checkNotNull(namespace, "namespace cannot be null"); | ||
| this.icebergCatalog = Preconditions.checkNotNull(icebergCatalog, "icebergCatalog cannot be null"); | ||
| this.icebergFilter = icebergFilter; | ||
| this.snapshotTime = snapshotTime; | ||
| this.residualFilterMode = Configs.valueOrDefault(residualFilterMode, ResidualFilterMode.IGNORE); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getTableName() | ||
| { | ||
| return tableName; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getNamespace() | ||
| { | ||
| return namespace; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public IcebergCatalog getIcebergCatalog() | ||
| { | ||
| return icebergCatalog; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public IcebergFilter getIcebergFilter() | ||
| { | ||
| return icebergFilter; | ||
| } | ||
|
|
||
| @Nullable | ||
| @JsonProperty | ||
| public DateTime getSnapshotTime() | ||
| { | ||
| return snapshotTime; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public ResidualFilterMode getResidualFilterMode() | ||
| { | ||
| return residualFilterMode; | ||
| } | ||
|
|
||
| protected Table retrieveTable() | ||
| { | ||
| return icebergCatalog.retrieveTable(namespace, tableName); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * 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.druid.iceberg.input; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import org.apache.druid.data.input.InputFormat; | ||
| import org.apache.druid.data.input.InputRowSchema; | ||
| import org.apache.druid.data.input.InputSource; | ||
| import org.apache.druid.data.input.InputSourceReader; | ||
| import org.apache.druid.iceberg.filter.IcebergFilter; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.TableScan; | ||
| import org.joda.time.DateTime; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.io.File; | ||
|
|
||
| public class IcebergArrowInputSource extends AbstractIcebergInputSource implements InputSource | ||
| { | ||
| public static final String TYPE_KEY = "iceberg_arrow"; | ||
|
|
||
| @JsonProperty | ||
| private final int arrowBatchSize; | ||
|
|
||
| @JsonCreator | ||
| public IcebergArrowInputSource( | ||
| @JsonProperty("tableName") String tableName, | ||
| @JsonProperty("namespace") String namespace, | ||
| @JsonProperty("icebergFilter") @Nullable IcebergFilter icebergFilter, | ||
| @JsonProperty("icebergCatalog") IcebergCatalog icebergCatalog, | ||
| @JsonProperty("snapshotTime") @Nullable DateTime snapshotTime, | ||
| @JsonProperty("residualFilterMode") @Nullable ResidualFilterMode residualFilterMode, | ||
| @JsonProperty("arrowBatchSize") @Nullable Integer arrowBatchSize | ||
| ) | ||
| { | ||
| super(tableName, namespace, icebergFilter, icebergCatalog, snapshotTime, residualFilterMode); | ||
| this.arrowBatchSize = arrowBatchSize != null && arrowBatchSize > 0 | ||
| ? arrowBatchSize | ||
| : IcebergArrowInputSourceReader.DEFAULT_BATCH_SIZE; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public int getArrowBatchSize() | ||
| { | ||
| return arrowBatchSize; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsFormat() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSplittable() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public InputSourceReader reader( | ||
| InputRowSchema inputRowSchema, | ||
| @Nullable InputFormat inputFormat, | ||
| File temporaryDirectory | ||
| ) | ||
| { | ||
| final Table table = retrieveTable(); | ||
| if (icebergFilter != null) { | ||
| final TableScan filteredScan = icebergFilter.filter( | ||
| table.newScan().caseSensitive(icebergCatalog.isCaseSensitive()) | ||
| ); | ||
| icebergCatalog.enforceResidualMode(filteredScan, getResidualFilterMode()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Apply snapshotTime before residual enforcement reader() checks residuals on a filtered scan built from table.newScan(), but snapshotTime is only applied later inside IcebergArrowInputSourceReader.buildScan(). With residualFilterMode=FAIL, historical ingestion can throw or pass based on the current snapshot rather than the snapshot actually being read. Apply asOfTime(snapshotTime.getMillis()) before enforceResidualMode, or move enforcement into the reader after the snapshot is selected. |
||
| } | ||
| return new IcebergArrowInputSourceReader( | ||
| table, | ||
| icebergFilter, | ||
| snapshotTime, | ||
| icebergCatalog.isCaseSensitive(), | ||
| inputRowSchema, | ||
| arrowBatchSize | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Register new Arrow dependencies in licenses.yaml
This module adds iceberg-arrow, arrow-vector, and arrow-memory-unsafe, while the root pom also manages arrow-memory-netty, but licenses.yaml has no Arrow or Iceberg Arrow entries. dev/license.md says new library dependencies must be registered there, so binary license/notice generation is incomplete until these artifacts are added.