-
Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-7879 Tests for EXPLAIN text and ExplainPlanAttributes serialization compatibility #2495
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f70827c
PHOENIX-7879 Tests for EXPLAIN text and ExplainPlanAttributes seriali…
apurtell bf3e3c0
Address review feedback
apurtell 6f038a9
Additional review feedback
apurtell 7251787
Rename ExplainOracleTest.java -> ExplainCompatibilityTest.java
apurtell 8491f2b
Rename class setup method to setUp
apurtell 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
61 changes: 61 additions & 0 deletions
61
...x-core-client/src/main/java/org/apache/phoenix/compile/RegionLocationsListSerializer.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,61 @@ | ||
| /* | ||
| * 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.phoenix.compile; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import org.apache.hadoop.hbase.HRegionLocation; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
|
|
||
| /** | ||
| * Jackson serializer for {@code List<HRegionLocation>} as it appears on | ||
| * {@link ExplainPlanAttributes#getRegionLocations()}. The HBase {@code HRegionLocation} bean is not | ||
| * cleanly serializable by Jackson's default introspection. | ||
| */ | ||
| public class RegionLocationsListSerializer extends StdSerializer<List<HRegionLocation>> { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public RegionLocationsListSerializer() { | ||
| super((Class<List<HRegionLocation>>) (Class<?>) List.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void serialize(List<HRegionLocation> value, JsonGenerator gen, SerializerProvider provider) | ||
| throws IOException { | ||
| gen.writeStartArray(); | ||
| for (HRegionLocation loc : value) { | ||
| gen.writeStartObject(); | ||
| RegionInfo region = loc == null ? null : loc.getRegion(); | ||
| gen.writeStringField("startKey", | ||
| region == null ? null : Bytes.toStringBinary(region.getStartKey())); | ||
| gen.writeStringField("endKey", | ||
| region == null ? null : Bytes.toStringBinary(region.getEndKey())); | ||
| ServerName sn = loc == null ? null : loc.getServerName(); | ||
| gen.writeStringField("server", sn == null ? null : sn.toString()); | ||
| gen.writeEndObject(); | ||
| } | ||
| gen.writeEndArray(); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
...ix-core-client/src/main/java/org/apache/phoenix/compile/ServerMergeColumnsSerializer.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,63 @@ | ||
| /* | ||
| * 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.phoenix.compile; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.apache.phoenix.schema.PColumn; | ||
|
|
||
| /** | ||
| * Jackson serializer for {@code Set<PColumn>} as it appears on | ||
| * {@link ExplainPlanAttributes#getServerMergeColumns()}. {@code PColumn} is an interface backed by | ||
| * implementations that are not Jackson-friendly. | ||
| */ | ||
| public class ServerMergeColumnsSerializer extends StdSerializer<Set<PColumn>> { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public ServerMergeColumnsSerializer() { | ||
| super((Class<Set<PColumn>>) (Class<?>) Set.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void serialize(Set<PColumn> value, JsonGenerator gen, SerializerProvider provider) | ||
| throws IOException { | ||
| List<String> names = new ArrayList<>(value.size()); | ||
| for (PColumn column : value) { | ||
| names.add(column == null ? null : column.toString()); | ||
| } | ||
| Collections.sort(names, (a, b) -> { | ||
| if (a == null && b == null) return 0; | ||
| if (a == null) return -1; | ||
| if (b == null) return 1; | ||
| return a.compareTo(b); | ||
| }); | ||
| gen.writeStartArray(); | ||
| for (String name : names) { | ||
| gen.writeString(name); | ||
| } | ||
| gen.writeEndArray(); | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainChangeRule.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,54 @@ | ||
| /* | ||
| * 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.phoenix.query.explain; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * The {@link ExplainOracle} freezes today's EXPLAIN output as a set of golden fixtures. Future | ||
| * EXPLAIN-design PRs that intentionally change the output register an {@code ExplainChangeRule} | ||
| * that rewrites the (frozen) form into the new expected form, so every change to the grammar is | ||
| * explicit and reviewable. | ||
| */ | ||
| public interface ExplainChangeRule { | ||
|
|
||
| /** | ||
| * Transform the golden plan steps text for the named case. The default implementation returns | ||
| * {@code goldenText} unchanged. | ||
| * @param caseId the corpus case identifier (e.g. {@code "pointLookup"}) | ||
| * @param goldenText the line-oriented golden as currently expected (already transformed by any | ||
| * earlier rule in the chain) | ||
| * @return the next-expected golden text (may be a new list or the same instance) | ||
| */ | ||
| default List<String> applyText(String caseId, List<String> goldenText) { | ||
| return goldenText; | ||
| } | ||
|
|
||
| /** | ||
| * Transform the golden JSON attributes tree for the named case. The default implementation | ||
| * returns {@code goldenJson} unchanged. | ||
| * @param caseId the corpus case identifier | ||
| * @param goldenJson the JSON attributes tree as currently expected (already transformed by any | ||
| * earlier rule in the chain) | ||
| * @return the next-expected JSON tree (may be a mutated input or a new node) | ||
| */ | ||
| default JsonNode applyJson(String caseId, JsonNode goldenJson) { | ||
| return goldenJson; | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainJsonNormalizer.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,71 @@ | ||
| /* | ||
| * 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.phoenix.query.explain; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.node.NullNode; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Elides cluster- and connection-specific fields from the JSON view of | ||
| * {@code ExplainPlanAttributes} so the comparison is invariant under environment differences. | ||
| */ | ||
| public final class ExplainJsonNormalizer { | ||
|
|
||
| private static final Pattern WAY_COUNT = Pattern.compile("\\b\\d+-WAY\\b"); | ||
|
|
||
| /** | ||
| * Recursively normalize the given attributes-shaped JSON node. | ||
| * @return the same node, for fluent chaining. | ||
| */ | ||
| public JsonNode normalize(JsonNode node) { | ||
| if (node == null || node.isNull() || !node.isObject()) { | ||
| return node; | ||
| } | ||
| ObjectNode obj = (ObjectNode) node; | ||
|
|
||
| if (obj.has("regionLocations")) { | ||
| obj.set("regionLocations", NullNode.getInstance()); | ||
| } | ||
| if (obj.has("numRegionLocationLookups")) { | ||
| obj.put("numRegionLocationLookups", 0); | ||
| } | ||
| if (obj.has("splitsChunk")) { | ||
| obj.set("splitsChunk", NullNode.getInstance()); | ||
| } | ||
| if (obj.has("estimatedRows")) { | ||
| obj.set("estimatedRows", NullNode.getInstance()); | ||
| } | ||
| if (obj.has("estimatedSizeInBytes")) { | ||
| obj.set("estimatedSizeInBytes", NullNode.getInstance()); | ||
| } | ||
|
|
||
| JsonNode iter = obj.get("iteratorTypeAndScanSize"); | ||
| if (iter != null && iter.isTextual()) { | ||
| obj.put("iteratorTypeAndScanSize", WAY_COUNT.matcher(iter.asText()).replaceAll("<N>-WAY")); | ||
| } | ||
|
|
||
| JsonNode rhs = obj.get("rhsJoinQueryExplainPlan"); | ||
| if (rhs != null && rhs.isObject()) { | ||
| normalize(rhs); | ||
| } | ||
|
|
||
| return obj; | ||
| } | ||
| } |
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.