-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bugs of aggregate column order mismatch
- Loading branch information
Showing
5 changed files
with
161 additions
and
53 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...gine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/ColumnOrder.java
This file contains 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,96 @@ | ||
/* | ||
* | ||
* * Copyright 2020 Alibaba Group Holding Limited. | ||
* * | ||
* * 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.alibaba.graphscope.cypher.antlr4.visitor; | ||
|
||
import com.alibaba.graphscope.common.ir.tools.GraphBuilder; | ||
import com.google.common.base.Objects; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* ColumnOrder keeps fields as the same order with RETURN clause | ||
*/ | ||
public class ColumnOrder { | ||
public static class Field { | ||
private final RexNode expr; | ||
private final String alias; | ||
|
||
public Field(RexNode expr, String alias) { | ||
this.expr = expr; | ||
this.alias = alias; | ||
} | ||
|
||
public RexNode getExpr() { | ||
return expr; | ||
} | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Field field = (Field) o; | ||
return Objects.equal(expr, field.expr) && Objects.equal(alias, field.alias); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(expr, alias); | ||
} | ||
} | ||
|
||
public interface FieldSupplier { | ||
Field get(RelDataType inputType); | ||
|
||
class Default implements FieldSupplier { | ||
private final GraphBuilder builder; | ||
private final Supplier<Integer> ordinalSupplier; | ||
|
||
public Default(GraphBuilder builder, Supplier<Integer> ordinalSupplier) { | ||
this.builder = builder; | ||
this.ordinalSupplier = ordinalSupplier; | ||
} | ||
|
||
@Override | ||
public Field get(RelDataType inputType) { | ||
String aliasName = inputType.getFieldList().get(ordinalSupplier.get()).getName(); | ||
return new Field(this.builder.variable(aliasName), aliasName); | ||
} | ||
} | ||
} | ||
|
||
private final List<FieldSupplier> fieldSuppliers; | ||
|
||
public ColumnOrder(List<FieldSupplier> fieldSuppliers) { | ||
this.fieldSuppliers = fieldSuppliers; | ||
} | ||
|
||
public @Nullable List<Field> getFields(RelDataType inputType) { | ||
return this.fieldSuppliers.stream().map(k -> k.get(inputType)).collect(Collectors.toList()); | ||
} | ||
} |
This file contains 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 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 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 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