-
Notifications
You must be signed in to change notification settings - Fork 2.9k
API, Core: Add scan planning apis to REST Catalog #11180
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: main
Are you sure you want to change the base?
Changes from all commits
b079591
fd70764
c68661f
9f57240
a42bc91
21d0fa3
136ca3b
619ef7f
990730e
24b8d47
782e4e3
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,34 @@ | ||
| /* | ||
| * 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.exceptions; | ||
|
|
||
| import com.google.errorprone.annotations.FormatMethod; | ||
|
|
||
| /** Exception raised when an entity is not found. */ | ||
| public class EntityNotFoundException extends RESTException implements CleanableFailure { | ||
| @FormatMethod | ||
| public EntityNotFoundException(String message, Object... args) { | ||
| super(message, args); | ||
| } | ||
|
|
||
| @FormatMethod | ||
| public EntityNotFoundException(Throwable cause, String message, Object... args) { | ||
| super(cause, message, args); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.apache.iceberg.expressions.Expression; | ||
| import org.apache.iceberg.expressions.ExpressionParser; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Sets; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| public class RESTFileScanTaskParser { | ||
| private static final String DATA_FILE = "data-file"; | ||
| private static final String DELETE_FILE_REFERENCES = "delete-file-references"; | ||
| private static final String RESIDUAL = "residual-filter"; | ||
|
|
||
| private RESTFileScanTaskParser() {} | ||
|
|
||
| public static void toJson( | ||
| FileScanTask fileScanTask, | ||
| Set<Integer> deleteFileReferences, | ||
| PartitionSpec partitionSpec, | ||
| JsonGenerator generator) | ||
| throws IOException { | ||
| Preconditions.checkArgument(fileScanTask != null, "Invalid file scan task: null"); | ||
| Preconditions.checkArgument(generator != null, "Invalid JSON generator: null"); | ||
|
|
||
| generator.writeStartObject(); | ||
| generator.writeFieldName(DATA_FILE); | ||
| ContentFileParser.unboundContentFileToJson(fileScanTask.file(), partitionSpec, generator); | ||
| if (deleteFileReferences != null) { | ||
| JsonUtil.writeIntegerArray(DELETE_FILE_REFERENCES, deleteFileReferences, generator); | ||
| } | ||
|
|
||
| if (fileScanTask.residual() != null) { | ||
| generator.writeFieldName(RESIDUAL); | ||
| ExpressionParser.toJson(fileScanTask.residual(), generator); | ||
| } | ||
| generator.writeEndObject(); | ||
| } | ||
|
|
||
| public static FileScanTask fromJson(JsonNode jsonNode, List<DeleteFile> allDeleteFiles) { | ||
| Preconditions.checkArgument(jsonNode != null, "Invalid JSON node for file scan task: null"); | ||
| Preconditions.checkArgument( | ||
| jsonNode.isObject(), "Invalid JSON node for file scan task: non-object (%s)", jsonNode); | ||
|
|
||
| UnboundGenericDataFile dataFile = | ||
| (UnboundGenericDataFile) | ||
| ContentFileParser.unboundContentFileFromJson(JsonUtil.get(DATA_FILE, jsonNode)); | ||
|
|
||
| UnboundGenericDeleteFile[] deleteFiles = null; | ||
| Set<Integer> deleteFileReferences = Sets.newHashSet(); | ||
| if (jsonNode.has(DELETE_FILE_REFERENCES)) { | ||
| deleteFileReferences.addAll(JsonUtil.getIntegerList(DELETE_FILE_REFERENCES, jsonNode)); | ||
| ImmutableList.Builder<UnboundGenericDeleteFile> builder = ImmutableList.builder(); | ||
| deleteFileReferences.forEach( | ||
| delIdx -> builder.add((UnboundGenericDeleteFile) allDeleteFiles.get(delIdx))); | ||
| deleteFiles = builder.build().toArray(new UnboundGenericDeleteFile[0]); | ||
| } | ||
|
|
||
| Expression filter = null; | ||
| if (jsonNode.has(RESIDUAL)) { | ||
| filter = ExpressionParser.fromJson(jsonNode.get(RESIDUAL)); | ||
| } | ||
|
|
||
| return new UnboundBaseFileScanTask(dataFile, deleteFiles, filter); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import java.util.Locale; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
|
||
| public enum RESTPlanningMode { | ||
| REQUIRED("required"), | ||
| SUPPORTED("supported"), | ||
| UNSUPPORTED("unsupported"); | ||
|
Contributor
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. I'm still going through the proposed spec change but I'm skeptical do we really need an explicit
Contributor
Author
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. I think thats also fair if we need to have an additional
Contributor
Author
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. Will let others chime in here though before making a revision.
Contributor
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. Sounds good. After some more thought, my 2c is that I think I'd rather us try and get the model + client side changes into 1.7 rather than expand the scope with this aspect since it's quite useful without these things defined. I'd rather not have client side changes depend on another spec change decision. For now, I think keeping it simple with a catalog client side property for controlling if server side planning is performed is the way forward. Once the model and client side changes are in, I think it'd make total sense to revisit the spec changes you mentioned and these specific planning mode changes. cc @rdblue @danielcweeks for their thoughts. |
||
| private final String planningMode; | ||
|
|
||
| RESTPlanningMode(String planningMode) { | ||
| this.planningMode = planningMode; | ||
| } | ||
|
|
||
| public String mode() { | ||
| return planningMode; | ||
| } | ||
|
|
||
| public static RESTPlanningMode fromName(String planningMode) { | ||
| Preconditions.checkArgument(planningMode != null, "planningMode is null"); | ||
| try { | ||
| return RESTPlanningMode.valueOf(planningMode.toUpperCase(Locale.ENGLISH)); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException( | ||
| String.format("Invalid planningMode name: %s", planningMode), e); | ||
| } | ||
| } | ||
| } | ||
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.
I don't think this is necessary, we should avoid it.
Uh oh!
There was an error while loading. Please reload this page.
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.
Agreed. @rahil-c could we just reuse the existing constructor for
GenericDataFileandGenericDeleteFileand copy over everything correctly with the new partition data during the binding? We should avoid exposing unnecessary public APIs when possibkeThere 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.
Ah BaseFile isn't public itself but still, think we should just avoid the extra method since it's possible to do everything via the constructor.