-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GIE Compiler] add arbitray array or map types to support ListLiteral…
… or MapLiteral in cypher
- Loading branch information
Showing
9 changed files
with
270 additions
and
14 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
...gine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryArrayType.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,48 @@ | ||
/* | ||
* 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.common.ir.type; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.type.AbstractSqlType; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* introduce a new array type to allow different component types in a single array, | ||
* to support {@code ListLiteral} in cypher, i.e. [a.name, a, b.age] | ||
*/ | ||
public class ArbitraryArrayType extends AbstractSqlType { | ||
private final List<RelDataType> componentTypes; | ||
|
||
public ArbitraryArrayType(List<RelDataType> componentTypes, boolean isNullable) { | ||
super(SqlTypeName.ARRAY, isNullable, null); | ||
this.componentTypes = ObjectUtils.requireNonEmpty(componentTypes); | ||
this.computeDigest(); | ||
} | ||
|
||
@Override | ||
protected void generateTypeString(StringBuilder sb, boolean withDetail) { | ||
sb.append("(" + this.componentTypes.toString() + ") ARRAY"); | ||
} | ||
|
||
public List<RelDataType> getComponentTypes() { | ||
return Collections.unmodifiableList(componentTypes); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryMapType.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,57 @@ | ||
/* | ||
* 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.common.ir.type; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.type.AbstractSqlType; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* introduce a new map type to allow different value types in a single map, | ||
* to support {@code MapLiteral} in cypher, i.e. [name: a.name, a: a, age: b.age] | ||
*/ | ||
public class ArbitraryMapType extends AbstractSqlType { | ||
private final RelDataType keyType; | ||
private final List<RelDataType> valueTypes; | ||
|
||
protected ArbitraryMapType( | ||
RelDataType keyType, List<RelDataType> valueTypes, boolean isNullable) { | ||
super(SqlTypeName.MAP, isNullable, null); | ||
this.keyType = Objects.requireNonNull(keyType); | ||
this.valueTypes = ObjectUtils.requireNonEmpty(valueTypes); | ||
this.computeDigest(); | ||
} | ||
|
||
@Override | ||
protected void generateTypeString(StringBuilder sb, boolean withDetail) { | ||
sb.append("(" + keyType.toString() + ", " + valueTypes.toString() + ") MAP"); | ||
} | ||
|
||
@Override | ||
public RelDataType getKeyType() { | ||
return this.keyType; | ||
} | ||
|
||
public List<RelDataType> getValueTypes() { | ||
return Collections.unmodifiableList(this.valueTypes); | ||
} | ||
} |
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
Oops, something went wrong.