Skip to content

Commit

Permalink
support flex data type in ir physical plan
Browse files Browse the repository at this point in the history
  • Loading branch information
shirly121 committed Dec 30, 2024
1 parent 4ea7570 commit fc6820b
Show file tree
Hide file tree
Showing 29 changed files with 774 additions and 694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.alibaba.graphscope.common.config.Configs;
import com.alibaba.graphscope.common.ir.meta.IrMeta;
import com.alibaba.graphscope.common.ir.meta.IrMetaStats;
import com.alibaba.graphscope.common.ir.meta.schema.GSDataTypeConvertor;
import com.alibaba.graphscope.common.ir.meta.schema.GSDataTypeDesc;
import com.alibaba.graphscope.common.ir.meta.schema.IrDataTypeConvertor;
import com.alibaba.graphscope.common.ir.meta.schema.IrGraphStatistics;
import com.alibaba.graphscope.common.ir.meta.schema.SchemaSpec;
import com.alibaba.graphscope.common.ir.rex.RexProcedureCall;
Expand Down Expand Up @@ -128,10 +128,17 @@ public Mode getMode() {
public static class Parameter {
private final String name;
private final RelDataType dataType;
// allow cast among types in the same family, i.e. int32 to int64, char to varchar
private final boolean allowCast;

public Parameter(String name, RelDataType dataType) {
this(name, dataType, false);
}

public Parameter(String name, RelDataType dataType, boolean allowCast) {
this.name = name;
this.dataType = dataType;
this.allowCast = allowCast;
}

public String getName() {
Expand All @@ -142,6 +149,10 @@ public RelDataType getDataType() {
return dataType;
}

public boolean allowCast() {
return allowCast;
}

@Override
public String toString() {
return "Parameter{" + "name='" + name + '\'' + ", dataType=" + dataType + '}';
Expand Down Expand Up @@ -171,8 +182,8 @@ public static void perform(StoredProcedureMeta meta, OutputStream outputStream)
}

private static Map<String, Object> createProduceMetaMap(StoredProcedureMeta meta) {
GSDataTypeConvertor<RelDataType> typeConvertor =
new GSDataTypeConvertor.Calcite(typeFactory);
IrDataTypeConvertor<GSDataTypeDesc> typeConvertor =
new IrDataTypeConvertor.Flex(typeFactory);
return ImmutableMap.of(
Config.NAME.getKey(),
meta.name,
Expand Down Expand Up @@ -216,8 +227,8 @@ private static Map<String, Object> createProduceMetaMap(StoredProcedureMeta meta

public static class Deserializer {
public static StoredProcedureMeta perform(InputStream inputStream) throws IOException {
GSDataTypeConvertor<RelDataType> typeConvertor =
new GSDataTypeConvertor.Calcite(typeFactory);
IrDataTypeConvertor<GSDataTypeDesc> typeConvertor =
new IrDataTypeConvertor.Flex(typeFactory);
Yaml yaml = new Yaml();
Map<String, Object> config = yaml.load(inputStream);
return new StoredProcedureMeta(
Expand All @@ -240,7 +251,7 @@ private static <T> T getValue(
}

private static RelDataType createReturnType(
List config, GSDataTypeConvertor<RelDataType> typeConvertor) {
List config, IrDataTypeConvertor<GSDataTypeDesc> typeConvertor) {
List<RelDataTypeField> fields = Lists.newArrayList();
if (config == null) {
return new RelRecordType(fields);
Expand All @@ -262,20 +273,24 @@ private static RelDataType createReturnType(
}

private static List<StoredProcedureMeta.Parameter> createParameters(
List config, GSDataTypeConvertor<RelDataType> typeConvertor) {
List config, IrDataTypeConvertor<GSDataTypeDesc> typeConvertor) {
List<StoredProcedureMeta.Parameter> parameters = Lists.newArrayList();
if (config == null) {
return parameters;
}
Iterator iterator = config.iterator();
while (iterator.hasNext()) {
Map<String, Object> field = (Map<String, Object>) iterator.next();
Object castValue = field.get("allow_cast");
boolean allowCast =
castValue == null ? false : Boolean.valueOf(String.valueOf(castValue));
parameters.add(
new StoredProcedureMeta.Parameter(
(String) field.get("name"),
typeConvertor.convert(
new GSDataTypeDesc(
(Map<String, Object>) field.get("type")))));
(Map<String, Object>) field.get("type"))),
allowCast));
}
return parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public IrMeta readMeta() throws IOException {
metaPair.getValue0(),
SnapshotId.createEmpty(), // todo: return snapshot id from http service
new IrGraphSchema(
configs,
new SchemaInputStream(
new ByteArrayInputStream(
metaInYaml.getBytes(StandardCharsets.UTF_8)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public IrMeta readMeta() throws IOException {
: SchemaSpec.Type.IR_CORE_IN_JSON;
IrGraphSchema graphSchema =
new IrGraphSchema(
configs,
new SchemaInputStream(
new FileInputStream(schemaPath.toFile()), schemaSpec));
IrMeta irMeta =
Expand Down

This file was deleted.

Loading

0 comments on commit fc6820b

Please sign in to comment.