Skip to content

Implement shallowEquals() for SampledRelation#10764

Merged
martint merged 1 commit intotrinodb:masterfrom
takezoe:sample-table-shallow-equals
Feb 1, 2022
Merged

Implement shallowEquals() for SampledRelation#10764
martint merged 1 commit intotrinodb:masterfrom
takezoe:sample-table-shallow-equals

Conversation

@takezoe
Copy link
Copy Markdown
Member

@takezoe takezoe commented Jan 24, 2022

TABLESAMPLE doesn't work inside a subquery.

For instance, the following query fails with java.lang.UnsupportedOperationException: not yet implemented: io.trino.sql.tree.SampledRelation on the latest master because SampledRelation doesn't implement shallowEquals().

SELECT * FROM system.runtime.queries WHERE query_id IN (
  SELECT query_id FROM system.runtime.queries TABLESAMPLE BERNOULLI(10)
);

Full stacktrace:

java.lang.UnsupportedOperationException: not yet implemented: io.trino.sql.tree.SampledRelation
	at io.trino.sql.tree.Node.shallowEquals(Node.java:60)
	at io.trino.sql.planner.ScopeAware.scopeAwareComparison(ScopeAware.java:137)
	at io.trino.sql.util.AstUtils.treeEqual(AstUtils.java:47)
	at io.trino.sql.util.AstUtils.treeEqual(AstUtils.java:61)
	at io.trino.sql.util.AstUtils.treeEqual(AstUtils.java:61)
	at io.trino.sql.util.AstUtils.treeEqual(AstUtils.java:61)
	at io.trino.sql.util.AstUtils.treeEqual(AstUtils.java:61)
	at io.trino.sql.planner.ScopeAware.equals(ScopeAware.java:94)
	at com.google.common.collect.SingletonImmutableBiMap.containsKey(SingletonImmutableBiMap.java:73)
	at io.trino.sql.planner.TranslationMap.canTranslate(TranslationMap.java:151)
	at io.trino.sql.planner.PlanBuilder.canTranslate(PlanBuilder.java:78)
	at io.trino.sql.planner.SubqueryPlanner.lambda$selectSubqueries$0(SubqueryPlanner.java:149)
	at com.google.common.graph.Traverser.validate(Traverser.java:367)
	at com.google.common.graph.Traverser.depthFirstPreOrder(Traverser.java:297)
	at com.google.common.graph.Traverser.depthFirstPreOrder(Traverser.java:283)
	at io.trino.sql.planner.SubqueryPlanner.selectSubqueries(SubqueryPlanner.java:156)
	at io.trino.sql.planner.SubqueryPlanner.handleSubqueries(SubqueryPlanner.java:127)
	at io.trino.sql.planner.QueryPlanner.filter(QueryPlanner.java:630)
	at io.trino.sql.planner.QueryPlanner.plan(QueryPlanner.java:394)
	at io.trino.sql.planner.RelationPlanner.visitQuerySpecification(RelationPlanner.java:983)
	at io.trino.sql.planner.RelationPlanner.visitQuerySpecification(RelationPlanner.java:131)
	at io.trino.sql.tree.QuerySpecification.accept(QuerySpecification.java:155)
	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
	at io.trino.sql.planner.QueryPlanner.planQueryBody(QueryPlanner.java:606)
	at io.trino.sql.planner.QueryPlanner.plan(QueryPlanner.java:193)
	at io.trino.sql.planner.RelationPlanner.visitQuery(RelationPlanner.java:976)
	at io.trino.sql.planner.RelationPlanner.visitQuery(RelationPlanner.java:131)
	at io.trino.sql.tree.Query.accept(Query.java:107)
	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
	at io.trino.sql.planner.LogicalPlanner.createRelationPlan(LogicalPlanner.java:769)
	at io.trino.sql.planner.LogicalPlanner.planStatementWithoutOutput(LogicalPlanner.java:291)
	at io.trino.sql.planner.LogicalPlanner.planStatement(LogicalPlanner.java:263)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:220)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:215)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:210)
	at io.trino.execution.SqlQueryExecution.doPlanQuery(SqlQueryExecution.java:474)
	at io.trino.execution.SqlQueryExecution.planQuery(SqlQueryExecution.java:455)
	at io.trino.execution.SqlQueryExecution.start(SqlQueryExecution.java:396)
	at io.trino.execution.SqlQueryManager.createQuery(SqlQueryManager.java:243)
	at io.trino.dispatcher.LocalDispatchQuery.lambda$startExecution$7(LocalDispatchQuery.java:143)
	at io.trino.$gen.Trino_dev____20220124_125301_2.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@cla-bot cla-bot bot added the cla-signed label Jan 24, 2022
@martint martint self-requested a review January 24, 2022 18:09
@findepi
Copy link
Copy Markdown
Member

findepi commented Jan 27, 2022

Shouldn't io.trino.sql.tree.Node#shallowEquals be abstract?

@takezoe
Copy link
Copy Markdown
Member Author

takezoe commented Jan 31, 2022

Shouldn't io.trino.sql.tree.Node#shallowEquals be abstract?

That would be effective to prevent missing implementations. By the way, is there any reason to keep this PR on hold? Is there a better way to solve the issue?

@martint
Copy link
Copy Markdown
Member

martint commented Jan 31, 2022

No, this solution is ok. There are some test failures that I haven’t had a chance to look at, yet. It’s probably a flakey test, but I need to verify that.

@martint martint merged commit 1c7d712 into trinodb:master Feb 1, 2022
@github-actions github-actions bot added this to the 370 milestone Feb 1, 2022
@takezoe
Copy link
Copy Markdown
Member Author

takezoe commented Feb 1, 2022

Thank you for merging this!

@takezoe takezoe deleted the sample-table-shallow-equals branch February 1, 2022 01:27
@martint martint mentioned this pull request Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants