-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Core: add labels to the load table/view read path #18045
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
Open
+767
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4cf923b
Core: add labels to the load table/view read path
laskoviymishka f2c0119
Core: rename fieldLabels to fieldLabel for single FieldLabel values
laskoviymishka 1161a1a
Core: preserve original null-check messages
laskoviymishka 44d8180
Core: address review comments on label tests and Labels.isEmpty
laskoviymishka ee93ef5
Core: default LoadTableResponse builder labels to Labels.EMPTY
laskoviymishka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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.Map; | ||
| import org.immutables.value.Value; | ||
|
|
||
| /** Labels attached to a single field, identified by its field id. See {@link Labels}. */ | ||
| @Value.Immutable | ||
| public interface FieldLabel { | ||
| int fieldId(); | ||
|
|
||
| Map<String, String> labels(); | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
core/src/main/java/org/apache/iceberg/FieldLabelParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * 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 org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| public class FieldLabelParser { | ||
| private static final String FIELD_ID = "field-id"; | ||
| private static final String LABELS = "labels"; | ||
|
|
||
| private FieldLabelParser() {} | ||
|
|
||
| public static String toJson(FieldLabel fieldLabel) { | ||
| return toJson(fieldLabel, false); | ||
| } | ||
|
|
||
| public static String toJson(FieldLabel fieldLabel, boolean pretty) { | ||
| return JsonUtil.generate(gen -> toJson(fieldLabel, gen), pretty); | ||
| } | ||
|
|
||
| public static void toJson(FieldLabel fieldLabel, JsonGenerator gen) throws IOException { | ||
| Preconditions.checkArgument(null != fieldLabel, "Invalid field labels: null"); | ||
|
|
||
| gen.writeStartObject(); | ||
|
|
||
| gen.writeNumberField(FIELD_ID, fieldLabel.fieldId()); | ||
| JsonUtil.writeStringMap(LABELS, fieldLabel.labels(), gen); | ||
|
|
||
| gen.writeEndObject(); | ||
| } | ||
|
|
||
| public static FieldLabel fromJson(String json) { | ||
| return JsonUtil.parse(json, FieldLabelParser::fromJson); | ||
| } | ||
|
|
||
| public static FieldLabel fromJson(JsonNode json) { | ||
| Preconditions.checkArgument(null != json, "Cannot parse field labels from null object"); | ||
|
|
||
| return ImmutableFieldLabel.builder() | ||
| .fieldId(JsonUtil.getInt(FIELD_ID, json)) | ||
| .labels(JsonUtil.getStringMap(LABELS, json)) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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.List; | ||
| import java.util.Map; | ||
| import org.immutables.value.Value; | ||
|
|
||
| /** Optional catalog-provided labels returned on a load response. */ | ||
| @Value.Immutable | ||
| public interface Labels { | ||
| Labels EMPTY = ImmutableLabels.builder().build(); | ||
|
|
||
| /** Object-level labels. */ | ||
| Map<String, String> objectLabels(); | ||
|
|
||
| /** Field-level labels */ | ||
| List<FieldLabel> fields(); | ||
|
|
||
| /** Returns true when there are neither object-level nor field-level labels. */ | ||
| @Value.Derived | ||
| default boolean isEmpty() { | ||
|
laskoviymishka marked this conversation as resolved.
|
||
| return objectLabels().isEmpty() && fields().isEmpty(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * 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 org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| public class LabelsParser { | ||
| private static final String OBJECT_LABELS = "object-labels"; | ||
| private static final String FIELDS = "fields"; | ||
|
|
||
| private LabelsParser() {} | ||
|
|
||
| public static String toJson(Labels labels) { | ||
| return toJson(labels, false); | ||
| } | ||
|
|
||
| public static String toJson(Labels labels, boolean pretty) { | ||
| return JsonUtil.generate(gen -> toJson(labels, gen), pretty); | ||
| } | ||
|
|
||
| public static void toJson(Labels labels, JsonGenerator gen) throws IOException { | ||
| Preconditions.checkArgument(null != labels, "Invalid labels: null"); | ||
|
|
||
| gen.writeStartObject(); | ||
|
|
||
| if (!labels.objectLabels().isEmpty()) { | ||
| JsonUtil.writeStringMap(OBJECT_LABELS, labels.objectLabels(), gen); | ||
| } | ||
|
|
||
| if (!labels.fields().isEmpty()) { | ||
| gen.writeArrayFieldStart(FIELDS); | ||
| for (FieldLabel fieldLabel : labels.fields()) { | ||
| FieldLabelParser.toJson(fieldLabel, gen); | ||
| } | ||
|
|
||
| gen.writeEndArray(); | ||
| } | ||
|
|
||
| gen.writeEndObject(); | ||
| } | ||
|
|
||
| public static Labels fromJson(String json) { | ||
| return JsonUtil.parse(json, LabelsParser::fromJson); | ||
| } | ||
|
|
||
| public static Labels fromJson(JsonNode json) { | ||
| Preconditions.checkArgument(null != json, "Cannot parse labels from null object"); | ||
|
|
||
| ImmutableLabels.Builder builder = ImmutableLabels.builder(); | ||
|
|
||
| if (json.hasNonNull(OBJECT_LABELS)) { | ||
| builder.objectLabels(JsonUtil.getStringMap(OBJECT_LABELS, json)); | ||
| } | ||
|
|
||
| if (json.hasNonNull(FIELDS)) { | ||
| builder.fields(JsonUtil.getObjectList(FIELDS, json, FieldLabelParser::fromJson)); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.