Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public Expr visitSlotReference(SlotReference slotReference, PlanTranslatorContex
}

@Override
public Expr visitArrayItemSlot(SlotReference slotReference, PlanTranslatorContext context) {
return context.findColumnRef(slotReference.getExprId());
public Expr visitArrayItemSlot(ArrayItemReference.ArrayItemSlot arrayItemSlot, PlanTranslatorContext context) {
return context.findColumnRef(arrayItemSlot.getExprId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.copier;

import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.ArrayItemReference;
import org.apache.doris.nereids.trees.expressions.Exists;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Expression;
Expand Down Expand Up @@ -70,15 +71,14 @@ public Expression visitAlias(Alias alias, DeepCopierContext context) {
@Override
public Expression visitSlotReference(SlotReference slotReference, DeepCopierContext context) {
Map<ExprId, ExprId> exprIdReplaceMap = context.exprIdReplaceMap;
ExprId newExprId;
if (exprIdReplaceMap.containsKey(slotReference.getExprId())) {
ExprId newExprId = exprIdReplaceMap.get(slotReference.getExprId());
return slotReference.withExprId(newExprId);
newExprId = exprIdReplaceMap.get(slotReference.getExprId());
} else {
SlotReference newOne = new SlotReference(slotReference.getName(), slotReference.getDataType(),
slotReference.nullable(), slotReference.getQualifier());
exprIdReplaceMap.put(slotReference.getExprId(), newOne.getExprId());
return newOne;
newExprId = StatementScopeIdGenerator.newExprId();
exprIdReplaceMap.put(slotReference.getExprId(), newExprId);
}
return slotReference.withExprId(newExprId);
}

@Override
Expand All @@ -105,6 +105,21 @@ public Expression visitVirtualReference(VirtualSlotReference virtualSlotReferenc
return newOne;
}

@Override
public Expression visitArrayItemReference(ArrayItemReference arrayItemSlot, DeepCopierContext context) {
Expression arrayExpression = arrayItemSlot.getArrayExpression().accept(this, context);
Map<ExprId, ExprId> exprIdReplaceMap = context.exprIdReplaceMap;
ArrayItemReference newOne;
if (exprIdReplaceMap.containsKey(arrayItemSlot.getExprId())) {
newOne = new ArrayItemReference(exprIdReplaceMap.get(arrayItemSlot.getExprId()),
arrayItemSlot.getName(), arrayExpression);
} else {
newOne = new ArrayItemReference(arrayItemSlot.getName(), arrayExpression);
exprIdReplaceMap.put(arrayItemSlot.getExprId(), newOne.getExprId());
}
return newOne;
}

@Override
public Expression visitExistsSubquery(Exists exists, DeepCopierContext context) {
LogicalPlan logicalPlan = LogicalPlanDeepCopier.INSTANCE.deepCopy(exists.getQueryPlan(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public List<DataType> expectedInputTypes() {
return ImmutableList.of(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX));
}

static class ArrayItemSlot extends SlotReference implements SlotNotFromChildren {
/**
* it is slot representation of ArrayItemReference
*/
public static class ArrayItemSlot extends SlotReference implements SlotNotFromChildren {
/**
* Constructor for SlotReference.
*
Expand All @@ -142,6 +145,11 @@ public ArrayItemSlot(ExprId exprId, String name, DataType dataType, boolean null
super(exprId, name, dataType, nullable, ImmutableList.of(), null, Optional.empty());
}

@Override
public ArrayItemSlot withExprId(ExprId exprId) {
return new ArrayItemSlot(exprId, name, dataType, nullable);
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArrayItemSlot(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public R visitSlotReference(SlotReference slotReference, C context) {
return visitSlot(slotReference, context);
}

public R visitArrayItemSlot(SlotReference arrayItemSlot, C context) {
return visit(arrayItemSlot, context);
public R visitArrayItemSlot(ArrayItemReference.ArrayItemSlot arrayItemSlot, C context) {
return visitSlotReference(arrayItemSlot, context);
}

public R visitMarkJoinReference(MarkJoinSlotReference markJoinSlotReference, C context) {
Expand Down Expand Up @@ -434,7 +434,7 @@ public R visitGroupingScalarFunction(GroupingScalarFunction groupingScalarFuncti
}

public R visitVirtualReference(VirtualSlotReference virtualSlotReference, C context) {
return visit(virtualSlotReference, context);
return visitSlotReference(virtualSlotReference, context);
}

public R visitArrayItemReference(ArrayItemReference arrayItemReference, C context) {
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/nereids_p0/subquery/test_subquery.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ true 15 1992 3021 11011920 0.000 true 9999-12-12 2015-04-02T00:00 3.141592653 2
-- !sql_subquery_one_row_relation --
1

-- !sql_mark_join --
1

Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ suite("test_subquery") {

qt_sql_subquery_one_row_relation """select * from test_one_row_relation;"""

qt_sql_mark_join """with A as (select count(*) n1 from test_one_row_relation where exists (select 1 from test_one_row_relation t where t.user_id = test_one_row_relation.user_id) or 1 = 1) select * from A;"""

sql """drop table if exists test_one_row_relation;"""
}