-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add quotes around printed domain values #16208
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 all commits
Commits
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
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
189 changes: 189 additions & 0 deletions
189
presto-main/src/test/java/com/facebook/presto/sql/planner/planPrinter/TestPlanPrinter.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,189 @@ | ||
| /* | ||
| * Licensed 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 com.facebook.presto.sql.planner.planPrinter; | ||
|
|
||
| import com.facebook.presto.common.predicate.Domain; | ||
| import com.facebook.presto.common.predicate.Range; | ||
| import com.facebook.presto.common.predicate.TupleDomain; | ||
| import com.facebook.presto.common.predicate.ValueSet; | ||
| import com.facebook.presto.cost.StatsAndCosts; | ||
| import com.facebook.presto.metadata.FunctionAndTypeManager; | ||
| import com.facebook.presto.operator.StageExecutionDescriptor; | ||
| import com.facebook.presto.spi.ColumnHandle; | ||
| import com.facebook.presto.spi.ConnectorId; | ||
| import com.facebook.presto.spi.TableHandle; | ||
| import com.facebook.presto.spi.plan.PlanNodeIdAllocator; | ||
| import com.facebook.presto.spi.plan.TableScanNode; | ||
| import com.facebook.presto.spi.relation.VariableReferenceExpression; | ||
| import com.facebook.presto.sql.planner.Partitioning; | ||
| import com.facebook.presto.sql.planner.PartitioningScheme; | ||
| import com.facebook.presto.sql.planner.PlanFragment; | ||
| import com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder; | ||
| import com.facebook.presto.sql.planner.plan.PlanFragmentId; | ||
| import com.facebook.presto.testing.TestingHandle; | ||
| import com.facebook.presto.testing.TestingMetadata; | ||
| import com.facebook.presto.testing.TestingTransactionHandle; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static com.facebook.presto.SessionTestUtils.TEST_SESSION; | ||
| import static com.facebook.presto.common.predicate.TupleDomain.withColumnDomains; | ||
| import static com.facebook.presto.common.type.VarcharType.VARCHAR; | ||
| import static com.facebook.presto.metadata.AbstractMockMetadata.dummyMetadata; | ||
| import static com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager; | ||
| import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION; | ||
| import static io.airlift.slice.Slices.utf8Slice; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| public class TestPlanPrinter | ||
| { | ||
| private static final PlanBuilder PLAN_BUILDER = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), dummyMetadata()); | ||
| private static final FunctionAndTypeManager FUNCTION_AND_TYPE_MANAGER = createTestFunctionAndTypeManager(); | ||
| private static final VariableReferenceExpression COLUMN_VARIABLE = new VariableReferenceExpression("column", VARCHAR); | ||
| private static final ColumnHandle COLUMN_HANDLE = new TestingMetadata.TestingColumnHandle("column"); | ||
| private static final TableHandle TABLE_HANDLE_WITH_LAYOUT = new TableHandle( | ||
| new ConnectorId("testConnector"), | ||
| new TestingMetadata.TestingTableHandle(), | ||
| TestingTransactionHandle.create(), | ||
| Optional.of(TestingHandle.INSTANCE)); | ||
|
|
||
| // Creates a trivial TableScan with the given domain on some column | ||
| private String domainToPrintedScan(VariableReferenceExpression variable, ColumnHandle colHandle, Domain domain) | ||
| { | ||
| TupleDomain<ColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.<ColumnHandle, Domain>builder().put(colHandle, domain).build()); | ||
|
|
||
| TableScanNode scanNode = PLAN_BUILDER.tableScan( | ||
| TABLE_HANDLE_WITH_LAYOUT, | ||
| ImmutableList.of(variable), | ||
| ImmutableMap.of(variable, colHandle), | ||
| tupleDomain, | ||
| tupleDomain); | ||
|
|
||
| PlanFragment testFragment = new PlanFragment( | ||
| new PlanFragmentId(0), | ||
| scanNode, | ||
| ImmutableSet.of(variable), | ||
| SOURCE_DISTRIBUTION, | ||
| ImmutableList.of(scanNode.getId()), | ||
| new PartitioningScheme(Partitioning.create(SOURCE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), | ||
| StageExecutionDescriptor.ungroupedExecution(), | ||
| false, | ||
| StatsAndCosts.empty(), | ||
| Optional.empty()); | ||
|
|
||
| return PlanPrinter.textPlanFragment(testFragment, FUNCTION_AND_TYPE_MANAGER, TEST_SESSION, false); | ||
| } | ||
|
|
||
| // Asserts that the PlanPrinter output for this domain is what was expected | ||
| private void assertDomainFormat(VariableReferenceExpression variable, ColumnHandle colHandle, Domain domain, String expected) | ||
| { | ||
| String printed = domainToPrintedScan(variable, colHandle, domain); | ||
| assertTrue(printed.contains(":: " + expected)); | ||
| } | ||
|
|
||
| private void assertDomainFormat(Domain domain, String expected) | ||
| { | ||
| assertDomainFormat(COLUMN_VARIABLE, COLUMN_HANDLE, domain, expected); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDomainTextFormatting() | ||
| { | ||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.all(VARCHAR), | ||
| false), | ||
| "[(<min>, <max>)]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("some string")), | ||
| false), | ||
| "[[\"some string\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("here's a quote: \"")), | ||
| false), | ||
| "[[\"here's a quote: \\\"\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("")), | ||
| false), | ||
| "[[\"\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.ofRanges( | ||
| Range.greaterThanOrEqual(VARCHAR, utf8Slice("string with \"quotes\" inside")) | ||
| .intersect(Range.lessThanOrEqual(VARCHAR, utf8Slice("this string's quote is here -> \"")))), | ||
| false), | ||
| "[[\"string with \\\"quotes\\\" inside\", \"this string's quote is here -> \\\"\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.ofRanges( | ||
| Range.greaterThan(VARCHAR, utf8Slice("string with \"quotes\" inside")) | ||
| .intersect(Range.lessThan(VARCHAR, utf8Slice("this string's quote is here -> \"")))), | ||
| false), | ||
| "[(\"string with \\\"quotes\\\" inside\", \"this string's quote is here -> \\\"\")]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("<min>")), | ||
| false), | ||
| "[[\"<min>\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("<max>")), | ||
| false), | ||
| "[[\"<max>\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("<min>, <max>")), | ||
| false), | ||
| "[[\"<min>, <max>\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.ofRanges( | ||
| Range.greaterThanOrEqual(VARCHAR, utf8Slice("a")) | ||
| .intersect(Range.lessThanOrEqual(VARCHAR, utf8Slice("b")))), | ||
| false), | ||
| "[[\"a\", \"b\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("a, b")), | ||
| false), | ||
| "[[\"a, b\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.create( | ||
| ValueSet.of(VARCHAR, utf8Slice("xyz")), | ||
| true), | ||
| "[NULL, [\"xyz\"]]"); | ||
|
|
||
| assertDomainFormat( | ||
| Domain.onlyNull(VARCHAR), | ||
| "[NULL]"); | ||
| } | ||
| } |
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.
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.
How about if if have field value as
'<min>' or '<max>'? Please add a test for that.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.
done