Skip to content

Commit

Permalink
support flex type in physical proto
Browse files Browse the repository at this point in the history
  • Loading branch information
shirly121 committed Dec 27, 2024
1 parent a5fc017 commit 9238a28
Show file tree
Hide file tree
Showing 64 changed files with 2,423 additions and 3,063 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static void perform(StoredProcedureMeta meta, OutputStream outputStream)

private static Map<String, Object> createProduceMetaMap(StoredProcedureMeta meta) {
GSDataTypeConvertor<RelDataType> typeConvertor =
GSDataTypeConvertor.Factory.create(RelDataType.class, typeFactory);
new GSDataTypeConvertor.Calcite(typeFactory);
return ImmutableMap.of(
Config.NAME.getKey(),
meta.name,
Expand Down Expand Up @@ -217,7 +217,7 @@ private static Map<String, Object> createProduceMetaMap(StoredProcedureMeta meta
public static class Deserializer {
public static StoredProcedureMeta perform(InputStream inputStream) throws IOException {
GSDataTypeConvertor<RelDataType> typeConvertor =
GSDataTypeConvertor.Factory.create(RelDataType.class, typeFactory);
new GSDataTypeConvertor.Calcite(typeFactory);
Yaml yaml = new Yaml();
Map<String, Object> config = yaml.load(inputStream);
return new StoredProcedureMeta(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@

package com.alibaba.graphscope.common.ir.meta.schema;

import com.alibaba.graphscope.proto.type.Common;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.util.JsonFormat;

import java.util.Map;

public class GSDataTypeDesc {
// support more format of GSDataTypeDesc, i.e. JSON, proto, etc.
private final Map<String, Object> yamlDesc;

// flex type in proto format
private Common.DataType protoDesc;

public GSDataTypeDesc(Map<String, Object> yamlDesc) {
this.yamlDesc = yamlDesc;
}
Expand All @@ -32,6 +39,15 @@ public Map<String, Object> getYamlDesc() {
return yamlDesc;
}

public Common.DataType getProtoDesc() throws Exception {
if (protoDesc != null) return protoDesc;
Common.DataType.Builder protoBuilder = Common.DataType.newBuilder();
String jsonDesc = new ObjectMapper().writeValueAsString(yamlDesc);
JsonFormat.parser().merge(jsonDesc, protoBuilder);
protoDesc = protoBuilder.build();
return protoDesc;
}

public String toString() {
return yamlDesc.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public static final GraphSchema buildSchemaFromYaml(String schemaYaml) {
Map<String, GraphVertex> vertexMap = Maps.newHashMap();
Map<String, GraphEdge> edgeMap = Maps.newHashMap();
Map<String, Integer> propNameToIdMap = Maps.newHashMap();
GSDataTypeConvertor<DataType> typeConvertor =
GSDataTypeConvertor.Factory.create(DataType.class, null);
GSDataTypeConvertor<DataType> typeConvertor = new GSDataTypeConvertor.Groot();
builderGraphElementFromYaml(
(List)
Objects.requireNonNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

package com.alibaba.graphscope.common.ir.runtime.proto;

import com.alibaba.graphscope.common.ir.meta.schema.GSDataTypeConvertor;
import com.alibaba.graphscope.common.ir.rel.type.group.GraphAggCall;
import com.alibaba.graphscope.common.ir.rex.RexVariableAliasCollector;
import com.alibaba.graphscope.common.ir.tools.AliasInference;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
import com.alibaba.graphscope.common.ir.type.GraphLabelType;
import com.alibaba.graphscope.common.ir.type.GraphNameOrId;
import com.alibaba.graphscope.common.ir.type.GraphPathType;
import com.alibaba.graphscope.common.ir.type.GraphProperty;
import com.alibaba.graphscope.common.ir.type.GraphSchemaType;
import com.alibaba.graphscope.common.ir.type.*;
import com.alibaba.graphscope.gaia.proto.*;
import com.alibaba.graphscope.gaia.proto.GraphAlgebra.GroupBy.AggFunc.Aggregate;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -274,54 +271,13 @@ public static final OuterExpression.ExprOpr protoOperator(SqlOperator operator)
}
}

Check notice on line 273 in interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java#L162-L273

Complex Method
public static final Common.DataType protoBasicDataType(RelDataType basicType) {
// hack ways: convert interval type to int64 to avoid complexity
if (basicType instanceof IntervalSqlType) return Common.DataType.INT64;
if (basicType instanceof GraphLabelType) return Common.DataType.INT32;
switch (basicType.getSqlTypeName()) {
case NULL:
return Common.DataType.NONE;
case BOOLEAN:
return Common.DataType.BOOLEAN;
case INTEGER:
return Common.DataType.INT32;
case BIGINT:
return Common.DataType.INT64;
case CHAR:
return Common.DataType.STRING;
case DECIMAL:
case FLOAT:
case DOUBLE:
return Common.DataType.DOUBLE;
case MULTISET:
case ARRAY:
RelDataType elementType = basicType.getComponentType();
switch (elementType.getSqlTypeName()) {
case INTEGER:
return Common.DataType.INT32_ARRAY;
case BIGINT:
return Common.DataType.INT64_ARRAY;
case CHAR:
return Common.DataType.STRING_ARRAY;
case DECIMAL:
case FLOAT:
case DOUBLE:
return Common.DataType.DOUBLE_ARRAY;
default:
throw new UnsupportedOperationException(
"array of element type "
+ elementType.getSqlTypeName()
+ " is unsupported yet");
}
case DATE:
return Common.DataType.DATE32;
case TIME:
return Common.DataType.TIME32;
case TIMESTAMP:
return Common.DataType.TIMESTAMP;
default:
throw new UnsupportedOperationException(
"basic type " + basicType.getSqlTypeName() + " is unsupported yet");
public static final com.alibaba.graphscope.proto.type.Common.DataType protoBasicDataType(
RelDataType basicType) {
try {
GSDataTypeConvertor convertor = new GSDataTypeConvertor.Calcite(null);
return convertor.convert(basicType).getProtoDesc();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

Expand Down
Loading

0 comments on commit 9238a28

Please sign in to comment.