Skip to content
Open
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 @@ -39,7 +39,9 @@
BYTES_LIST(15),
DATE(16), // represent DATE32
TIME32(17),
TIMESTAMP(18);
TIMESTAMP(18),
UINT(19),
ULONG(20);

private final byte type;

Expand All @@ -47,49 +49,53 @@
this.type = (byte) type;
}

public static DataType parseProto(DataTypePb pb) {
switch (pb) {
case UNKNOWN:
return DataType.UNKNOWN;
case BOOL:
return DataType.BOOL;
case CHAR:
return DataType.CHAR;
case SHORT:
return DataType.SHORT;
case INT:
return DataType.INT;
case LONG:
return DataType.LONG;
case FLOAT:
return DataType.FLOAT;
case DOUBLE:
return DataType.DOUBLE;
case STRING:
return DataType.STRING;
case BYTES:
return DataType.BYTES;
case INT_LIST:
return DataType.INT_LIST;
case LONG_LIST:
return DataType.LONG_LIST;
case FLOAT_LIST:
return DataType.FLOAT_LIST;
case DOUBLE_LIST:
return DataType.DOUBLE_LIST;
case STRING_LIST:
return DataType.STRING_LIST;
case DATE32:
return DataType.DATE;
case TIME32_MS:
return DataType.TIME32;
case TIMESTAMP_MS:
return DataType.TIMESTAMP;
case UINT:
return DataType.UINT;
case ULONG:
return DataType.ULONG;
default:
throw new InvalidDataTypeException("Unknown DataType: [" + pb + "]");
}
}

Check notice on line 98 in interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java#L52-L98

Complex Method
public static DataType parseString(String type) {
String upperType = type.toUpperCase();
if (upperType.startsWith("LIST<")) {
Expand All @@ -101,49 +107,53 @@
}
}

public DataTypePb toProto() {
switch (this) {
case UNKNOWN:
return DataTypePb.UNKNOWN;
case BOOL:
return DataTypePb.BOOL;
case CHAR:
return DataTypePb.CHAR;
case SHORT:
return DataTypePb.SHORT;
case INT:
return DataTypePb.INT;
case LONG:
return DataTypePb.LONG;
case FLOAT:
return DataTypePb.FLOAT;
case DOUBLE:
return DataTypePb.DOUBLE;
case STRING:
return DataTypePb.STRING;
case BYTES:
return DataTypePb.BYTES;
case INT_LIST:
return DataTypePb.INT_LIST;
case LONG_LIST:
return DataTypePb.LONG_LIST;
case FLOAT_LIST:
return DataTypePb.FLOAT_LIST;
case DOUBLE_LIST:
return DataTypePb.DOUBLE_LIST;
case STRING_LIST:
return DataTypePb.STRING_LIST;
case DATE:
return DataTypePb.DATE32;
case TIME32:
return DataTypePb.TIME32_MS;
case TIMESTAMP:
return DataTypePb.TIMESTAMP_MS;
case UINT:
return DataTypePb.UINT;
case ULONG:
return DataTypePb.ULONG;
default:
throw new UnsupportedOperationException("Unsupported DataType: [" + this + "]");
}
}

Check notice on line 156 in interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java#L110-L156

Complex Method
@Override
public String toString() {
String dataTypeString = this.name();
Expand Down Expand Up @@ -188,81 +198,81 @@
}
}

public static DataType parseFromDataType(
com.alibaba.graphscope.groot.common.meta.DataType dataType) {
InternalDataType internalDataType = dataType.getType();
switch (internalDataType) {
case BOOL:
return DataType.BOOL;

case CHAR:
return DataType.CHAR;

case SHORT:
return DataType.SHORT;

case INT:
return DataType.INT;

case LONG:
return DataType.LONG;

case FLOAT:
return DataType.FLOAT;

case DOUBLE:
return DataType.DOUBLE;

case STRING:
return DataType.STRING;

case DATE:
return DataType.DATE;

case TIME:
return DataType.TIME32;

case TIMESTAMP:
return DataType.TIMESTAMP;

case BYTES:
return DataType.BYTES;

case LIST:
{
switch (InternalDataType.valueOf(dataType.getExpression())) {
case INT:
{
return DataType.INT_LIST;
}
case LONG:
{
return DataType.LONG_LIST;
}
case FLOAT:
{
return DataType.FLOAT_LIST;
}
case DOUBLE:
{
return DataType.DOUBLE_LIST;
}
case STRING:
{
return DataType.STRING_LIST;
}
default:
{
throw new InvalidDataTypeException(
"Unsupported property data type " + dataType);
}
}
}
default:
{
throw new InvalidDataTypeException(
"Unsupported property data type " + dataType);
}
}
}

Check notice on line 277 in interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/DataType.java#L201-L277

Complex Method
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
import com.alibaba.graphscope.groot.common.exception.IllegalStateException;
import com.alibaba.graphscope.groot.common.exception.InvalidArgumentException;
import com.alibaba.graphscope.proto.groot.PropertyValuePb;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLong;
import com.google.protobuf.ByteString;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Objects;

Expand All @@ -37,47 +44,116 @@
this.valObject = valObject;
}

private static Object stringToObj(DataType dataType, Object val) {
String valString;
if (val instanceof String) {
valString = (String) val;
} else {
return val;
}
try {
switch (dataType) {
case BOOL:
return Boolean.parseBoolean(valString);
case CHAR:
return valString.charAt(0);
case SHORT:
return Short.valueOf(valString);
case INT:
return Integer.valueOf(valString);
case UINT:
return UnsignedInteger.valueOf(valString);
case LONG:
return Long.valueOf(valString);
case ULONG:
return UnsignedLong.valueOf(valString);
case FLOAT:
return Float.valueOf(valString);
case DOUBLE:
return Double.valueOf(valString);
case STRING:
return valString;
case DATE:
return parseDate(valString);
case TIME32:
return parseTime32(valString);
case TIMESTAMP:
return parseTimestamp(valString);
default:
throw new IllegalStateException("Unexpected value: " + dataType);
}
} catch (Exception e) {
throw new InvalidArgumentException(
"unable to parse object to bytes. DataType ["
+ dataType
+ "], Object ["
+ valString
+ "], class ["
+ valString.getClass()
+ "]",
e);
}
}

private static Integer parseDate(String valString) {
try {
return Integer.valueOf(valString);
} catch (Exception e) {
try {
LocalDate date = LocalDate.parse(valString, DateTimeFormatter.ISO_LOCAL_DATE);
long epochDays = date.toEpochDay();
return (int) epochDays;
} catch (Exception e1) {
throw new InvalidArgumentException(
"Unable to parse date string to date. Object ["
+ valString
+ "], class ["
+ valString.getClass()
+ "].",
e1);
}
}
}

private static Integer parseTime32(String valString) {
try {
return Integer.valueOf(valString);
} catch (Exception e) {
try {
LocalTime time = LocalTime.parse(valString, DateTimeFormatter.ISO_LOCAL_TIME);
return time.toSecondOfDay();
} catch (Exception e1) {
throw new InvalidArgumentException(
"Unable to parse time32 string to int. Object ["
+ valString
+ "], class ["
+ valString.getClass()
+ "].",
e1);
}
}
}

private static Long parseTimestamp(String valString) {
try {
return Long.valueOf(valString);
} catch (Exception e) {
try {
LocalDateTime dateTime =
LocalDateTime.parse(valString, DateTimeFormatter.ISO_DATE_TIME);
return dateTime.toEpochSecond(ZoneOffset.UTC) * 1000;
} catch (Exception e1) {
throw new InvalidArgumentException(
"Unable to parse timestamp string to long. Object ["
+ valString
+ "], class ["
+ valString.getClass()
+ "].",

Check notice on line 151 in interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/PropertyValue.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/PropertyValue.java#L47-L151

Complex Method
e1);
}
}
}

public static PropertyValue parseProto(PropertyValuePb proto) {
try {
DataType dataType = DataType.parseProto(proto.getDataType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
return ByteBuffer.allocate(Integer.BYTES)
.putInt(Integer.valueOf(valObject.toString()))
.array();
case UINT:
int uintValue = Integer.parseUnsignedInt(valObject.toString());
return ByteBuffer.allocate(Integer.BYTES).putInt(uintValue).array();
case LONG:
return ByteBuffer.allocate(Long.BYTES)
.putLong(Long.valueOf(valObject.toString()))
.array();
case ULONG:
long ulongValue = Long.parseUnsignedLong(valObject.toString());
return ByteBuffer.allocate(Long.BYTES).putLong(ulongValue).array();
case FLOAT:
return ByteBuffer.allocate(Float.BYTES)
.putFloat(Float.valueOf(valObject.toString()))
Expand Down Expand Up @@ -148,6 +154,18 @@
dos.write(bytes);
}
return bos.toByteArray();
case DATE:
return ByteBuffer.allocate(Integer.BYTES)
.putInt(Integer.valueOf(valObject.toString()))
.array();
case TIME32:
return ByteBuffer.allocate(Integer.BYTES)
.putInt(Integer.valueOf(valObject.toString()))
.array();
case TIMESTAMP:
return ByteBuffer.allocate(Long.BYTES)
.putLong(Long.valueOf(valObject.toString()))
.array();
default:
throw new IllegalStateException("Unexpected value: " + dataType);
}
Expand All @@ -164,116 +182,116 @@
}
}

public static Object bytesToObject(DataType dataType, byte[] valBytes) {
try {
Object valObject;
switch (dataType) {
case BOOL:
valObject = valBytes[0] != (byte) 0;
break;
case CHAR:
valObject = ByteBuffer.wrap(valBytes).getChar();
break;
case SHORT:
valObject = ByteBuffer.wrap(valBytes).getShort();
break;
case INT:
valObject = ByteBuffer.wrap(valBytes).getInt();
break;
case LONG:
valObject = ByteBuffer.wrap(valBytes).getLong();
break;
case FLOAT:
valObject = ByteBuffer.wrap(valBytes).getFloat();
break;
case DOUBLE:
valObject = ByteBuffer.wrap(valBytes).getDouble();
break;
case STRING:
valObject = new String(valBytes, StandardCharsets.UTF_8);
break;
case BYTES:
valObject = valBytes;
break;
case INT_LIST:
valObject =
parseListVal(
valBytes,
dis -> {
try {
return dis.readInt();
} catch (IOException e) {
throw new InvalidArgumentException(
"parse val failed", e);
}
});
break;
case LONG_LIST:
valObject =
parseListVal(
valBytes,
dis -> {
try {
return dis.readLong();
} catch (IOException e) {
throw new InvalidArgumentException(
"parse val failed", e);
}
});
break;
case FLOAT_LIST:
valObject =
parseListVal(
valBytes,
dis -> {
try {
return dis.readFloat();
} catch (IOException e) {
throw new InvalidArgumentException(
"parse val failed", e);
}
});
break;
case DOUBLE_LIST:
valObject =
parseListVal(
valBytes,
dis -> {
try {
return dis.readDouble();
} catch (IOException e) {
throw new InvalidArgumentException(
"parse val failed", e);
}
});
break;
case STRING_LIST:
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(valBytes));
int size = dis.readInt();
List<Integer> strAccumulatedLength = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
strAccumulatedLength.add(dis.readInt());
}
List<String> list = new ArrayList<>(size);
if (size != 0) {
int len = strAccumulatedLength.get(0);
list.add(new String(readBytes(dis, len)));
for (int i = 1; i < size; i++) {
len = strAccumulatedLength.get(i) - strAccumulatedLength.get(i - 1);
list.add(new String(readBytes(dis, len)));
}
}
valObject = list;
break;
default:
throw new IllegalStateException("Unexpected value: " + dataType);
}
return valObject;
} catch (IOException e) {
throw new InvalidArgumentException("parse val failed", e);
}
}

Check notice on line 294 in interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/SerdeUtils.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/schema/wrapper/SerdeUtils.java#L185-L294

Complex Method
private static byte[] readBytes(DataInputStream dis, int len) throws IOException {
byte[] bytes = new byte[len];
dis.read(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

Expand All @@ -45,6 +46,15 @@
public interface IrDataTypeConvertor<T> {
Logger logger = LoggerFactory.getLogger(IrDataTypeConvertor.class);

// support unsigned type as decimal type with fixed precision and scale
int UINT32_PRECISION = 10;
int UINT32_SCALE = 0;
int UINT64_PRECISION = 20;
int UINT64_SCALE = 0;

BigDecimal UINT32_MAX = new BigDecimal("4294967295");
BigDecimal UINT64_MAX = new BigDecimal("18446744073709551615");

RelDataType convert(T dataFrom);

T convert(RelDataType dataFrom);
Expand All @@ -58,402 +68,410 @@
this.throwsOnFail = throwsOnFail;
}

@Override
public RelDataType convert(DataType from) {
requireNonNull(typeFactory, "typeFactory should not be null");
switch (from) {
case BOOL:
return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
case CHAR:
// single character
return typeFactory.createSqlType(SqlTypeName.CHAR, 1);
case STRING:
// string with unlimited length
return typeFactory.createSqlType(
SqlTypeName.VARCHAR, RelDataType.PRECISION_NOT_SPECIFIED);
case SHORT:
// 2-bytes signed integer
return typeFactory.createSqlType(SqlTypeName.SMALLINT);
case INT:
// 4-bytes signed integer
return typeFactory.createSqlType(SqlTypeName.INTEGER);
case UINT:
// 4-bytes unsigned integer
return typeFactory.createSqlType(
SqlTypeName.DECIMAL, UINT32_PRECISION, UINT32_SCALE);
case LONG:
// 8-bytes signed integer
return typeFactory.createSqlType(SqlTypeName.BIGINT);
case ULONG:
// 8-bytes unsigned integer
return typeFactory.createSqlType(
SqlTypeName.DECIMAL, UINT64_PRECISION, UINT64_SCALE);
case FLOAT:
// single precision floating point, 4 bytes
return typeFactory.createSqlType(SqlTypeName.FLOAT);
case DOUBLE:
// double precision floating point, 8 bytes
return typeFactory.createSqlType(SqlTypeName.DOUBLE);
case DATE:
// int32 days since 1970-01-01
return typeFactory.createSqlType(SqlTypeName.DATE);
case TIME32:
// int32 milliseconds past midnight
return typeFactory.createSqlType(SqlTypeName.TIME);
case TIMESTAMP:
// int64 milliseconds since 1970-01-01 00:00:00.000000
return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
case INT_LIST:
// array of 4-bytes signed integer, unlimited size
return typeFactory.createArrayType(
convert(DataType.INT), RelDataType.PRECISION_NOT_SPECIFIED);
case LONG_LIST:
// array of 8-bytes signed integer, unlimited size
return typeFactory.createArrayType(
convert(DataType.LONG), RelDataType.PRECISION_NOT_SPECIFIED);
case FLOAT_LIST:
// array of single precision floating point, unlimited size
return typeFactory.createArrayType(
convert(DataType.FLOAT), RelDataType.PRECISION_NOT_SPECIFIED);
case DOUBLE_LIST:
// array of double precision floating point, unlimited size
return typeFactory.createArrayType(
convert(DataType.DOUBLE), RelDataType.PRECISION_NOT_SPECIFIED);
case STRING_LIST:
// array of string, unlimited size
return typeFactory.createArrayType(
convert(DataType.STRING), RelDataType.PRECISION_NOT_SPECIFIED);
case UNKNOWN:
return typeFactory.createSqlType(SqlTypeName.UNKNOWN);
case BYTES:
case BYTES_LIST:
default:
if (throwsOnFail) {
throw new UnsupportedOperationException(
"convert GrootDataType ["
+ from.name()
+ "] to RelDataType is unsupported yet");
}
return typeFactory.createSqlType(SqlTypeName.ANY);
}
}

Check notice on line 150 in interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java#L71-L150

Complex Method
@Override
public DataType convert(RelDataType dataFrom) {
SqlTypeName typeName = dataFrom.getSqlTypeName();
switch (typeName) {
case BOOLEAN:
return DataType.BOOL;
case CHAR:
if (dataFrom.getPrecision() == 1) {
return DataType.CHAR;
}
break;
case VARCHAR:
if (dataFrom.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
return DataType.STRING;
}
break;
case SMALLINT:
return DataType.SHORT;
case INTEGER:
return DataType.INT;
case BIGINT:
return DataType.LONG;
case FLOAT:
return DataType.FLOAT;
case DOUBLE:
return DataType.DOUBLE;
case DATE:
return DataType.DATE;
case TIME:
return DataType.TIME32;
case TIMESTAMP:
return DataType.TIMESTAMP;
case MULTISET:
case ARRAY:
RelDataType componentType = dataFrom.getComponentType();
// check the array or set is an unlimited size list of primitive type
if (componentType != null
&& dataFrom.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
switch (componentType.getSqlTypeName()) {
case INTEGER:
return DataType.INT_LIST;
case BIGINT:
return DataType.LONG_LIST;
case FLOAT:
return DataType.FLOAT_LIST;
case DOUBLE:
return DataType.DOUBLE_LIST;
case VARCHAR:
if (componentType.getPrecision()
== RelDataType.PRECISION_NOT_SPECIFIED) {
return DataType.STRING_LIST;
}
}
}
break;
case UNKNOWN:
return DataType.UNKNOWN;
default:
}
if (throwsOnFail) {
throw new UnsupportedOperationException(
"convert RelDataType ["
+ dataFrom
+ "] to GrootDataType is unsupported yet");
}
return DataType.UNKNOWN;
}
}

class Flex implements IrDataTypeConvertor<GSDataTypeDesc> {
private final RelDataTypeFactory typeFactory;
private final boolean throwsOnFail;

Check notice on line 223 in interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java#L151-L223

Complex Method
public Flex(RelDataTypeFactory typeFactory, boolean throwsOnFail) {
this.typeFactory = typeFactory;
this.throwsOnFail = throwsOnFail;
}

@Override
public RelDataType convert(GSDataTypeDesc from) {
Objects.requireNonNull(typeFactory, "typeFactory should not be null");
Map<String, Object> typeMap = from.getYamlDesc();
Object value;
if ((value = typeMap.get("primitive_type")) != null) {
switch (value.toString()) {
case "DT_NULL":
return typeFactory.createSqlType(SqlTypeName.NULL);
case "DT_ANY":
// any type
return typeFactory.createSqlType(SqlTypeName.ANY);
case "DT_SIGNED_INT32":
// 4-bytes signed integer
return typeFactory.createSqlType(SqlTypeName.INTEGER);
case "DT_SIGNED_INT64":
// 8-bytes signed integer
return typeFactory.createSqlType(SqlTypeName.BIGINT);
case "DT_BOOL":
// boolean type
return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
case "DT_FLOAT":
// single precision floating point, 4 bytes
return typeFactory.createSqlType(SqlTypeName.FLOAT);
case "DT_DOUBLE":
// double precision floating point, 8 bytes
return typeFactory.createSqlType(SqlTypeName.DOUBLE);
}
} else if ((value = typeMap.get("string")) != null) {
Map<String, Object> strType = (Map<String, Object>) value;
if (strType.containsKey("long_text")) {
// string with unlimited length
return typeFactory.createSqlType(
SqlTypeName.VARCHAR, RelDataType.PRECISION_NOT_SPECIFIED);
} else if (strType.containsKey("char")) {
Object charValue = strType.get("char");
Integer fixedLen = getIntValue(charValue, "fixed_length");
if (fixedLen == null) {
fixedLen =
typeFactory.getTypeSystem().getDefaultPrecision(SqlTypeName.CHAR);
logger.warn(
"can not convert {} to a valid fixed length, use default"
+ " length {} instead",
charValue,
fixedLen);
}
// string with fixed length
return typeFactory.createSqlType(SqlTypeName.CHAR, fixedLen);
} else if (strType.containsKey("var_char")) {
Object varCharValue = strType.get("var_char");
Integer maxLen = getIntValue(varCharValue, "max_length");
if (maxLen == null) {
maxLen =
typeFactory
.getTypeSystem()
.getDefaultPrecision(SqlTypeName.VARCHAR);
logger.warn(
"can not convert {} to a valid max length, use default"
+ " length {} instead",
varCharValue,
maxLen);
}
// string with variable length, bound by max length
return typeFactory.createSqlType(SqlTypeName.VARCHAR, maxLen);
}
} else if ((value = typeMap.get("temporal")) != null) {
Map<String, Object> temporalType = (Map<String, Object>) value;
if (temporalType.containsKey("date32")) {
// int32 days since 1970-01-01
return typeFactory.createSqlType(SqlTypeName.DATE);
} else if (temporalType.containsKey("time32")) {
// int32 milliseconds past midnight
return typeFactory.createSqlType(SqlTypeName.TIME);
} else if (temporalType.containsKey("timestamp")) {
// int64 milliseconds since 1970-01-01 00:00:00.000000
return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
}
} else if ((value = typeMap.get("array")) != null) {
Map<String, Object> arrayType = (Map<String, Object>) value;
Map<String, Object> componentType =
(Map<String, Object>) arrayType.get("component_type");
Preconditions.checkArgument(
componentType != null, "field 'component_type' is required in array type");
// array of component type, unlimited size
return typeFactory.createArrayType(
convert(new GSDataTypeDesc(componentType)),
RelDataType.PRECISION_NOT_SPECIFIED);
} else if ((value = typeMap.get("map")) != null) {
Map<String, Object> mapType = (Map<String, Object>) value;
Map<String, Object> keyType = (Map<String, Object>) mapType.get("key_type");
Preconditions.checkArgument(
keyType != null, "field 'key_type' is required in map type");
Map<String, Object> valueType = (Map<String, Object>) mapType.get("value_type");
Preconditions.checkArgument(
valueType != null, "field 'value_type' is required in map type");
// map of key type to value type
return typeFactory.createMapType(
convert(new GSDataTypeDesc(keyType)),
convert(new GSDataTypeDesc(valueType)));
} else if ((value = typeMap.get("decimal")) != null) {
Integer precision = getIntValue(value, "precision");
if (precision == null) {
precision =
typeFactory.getTypeSystem().getDefaultPrecision(SqlTypeName.DECIMAL);
logger.warn(
"can not convert {} to a valid precision, use default"
+ " precision {} instead",
value,
precision);
}
Integer scale = getIntValue(value, "scale");
if (scale == null) {
scale = typeFactory.getTypeSystem().getMaxScale(SqlTypeName.DECIMAL);
logger.warn(
"can not convert {} to a valid scale, use max" + " scale {} instead",
value,
scale);
}
// decimal type with precision and scale
return typeFactory.createSqlType(SqlTypeName.DECIMAL, precision, scale);
}
if (throwsOnFail) {
throw new UnsupportedOperationException(
"convert GSDataTypeDesc [" + from + "] to RelDataType is unsupported yet");
}
return typeFactory.createSqlType(SqlTypeName.ANY);
}

Check notice on line 356 in interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java#L229-L356

Complex Method
@Override
public GSDataTypeDesc convert(RelDataType from) {
if (from instanceof IntervalSqlType) {
return new GSDataTypeDesc(ImmutableMap.of("primitive_type", "DT_SIGNED_INT64"));
} else if (from instanceof GraphLabelType) {
return new GSDataTypeDesc(ImmutableMap.of("primitive_type", "DT_SIGNED_INT32"));
}
SqlTypeName typeName = from.getSqlTypeName();
Map<String, Object> yamlDesc;
switch (typeName) {
case ANY:
yamlDesc = ImmutableMap.of("primitive_type", "DT_ANY");
break;
case NULL:
yamlDesc = ImmutableMap.of("primitive_type", "DT_NULL");
break;
case INTEGER:
yamlDesc = ImmutableMap.of("primitive_type", "DT_SIGNED_INT32");
break;
case BIGINT:
yamlDesc = ImmutableMap.of("primitive_type", "DT_SIGNED_INT64");
break;
case BOOLEAN:
yamlDesc = ImmutableMap.of("primitive_type", "DT_BOOL");
break;
case FLOAT:
yamlDesc = ImmutableMap.of("primitive_type", "DT_FLOAT");
break;
case DOUBLE:
yamlDesc = ImmutableMap.of("primitive_type", "DT_DOUBLE");
break;
case CHAR:
Map charMap = Maps.newHashMap();
charMap.put("char", ImmutableMap.of("fixed_length", from.getPrecision()));
yamlDesc = ImmutableMap.of("string", charMap);
break;
case VARCHAR:
if (from.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
Map longTextMap = Maps.newHashMap();
longTextMap.put("long_text", ImmutableMap.of());
yamlDesc = ImmutableMap.of("string", longTextMap);
} else {
Map varCharMap = Maps.newHashMap();
varCharMap.put(
"var_char", ImmutableMap.of("max_length", from.getPrecision()));
yamlDesc = ImmutableMap.of("string", varCharMap);
}
break;
case DATE:
Map dateMap = Maps.newHashMap();
dateMap.put("date32", ImmutableMap.of());
yamlDesc = ImmutableMap.of("temporal", dateMap);
break;
case TIME:
Map timeMap = Maps.newHashMap();
timeMap.put("time32", ImmutableMap.of());
yamlDesc = ImmutableMap.of("temporal", timeMap);
break;
case TIMESTAMP:
Map timestampMap = Maps.newHashMap();
timestampMap.put("timestamp", ImmutableMap.of());
yamlDesc = ImmutableMap.of("temporal", timestampMap);
break;
case ARRAY:
case MULTISET:
Map<String, Object> componentType;
if (from instanceof ArbitraryArrayType) {
componentType = ImmutableMap.of("primitive_type", "DT_ANY");
} else {
componentType = convert(from.getComponentType()).getYamlDesc();
}
yamlDesc =
ImmutableMap.of(
"array",
ImmutableMap.of(
"component_type",
componentType,
"max_length",
from.getPrecision()
== RelDataType.PRECISION_NOT_SPECIFIED
? Integer.MAX_VALUE
: from.getPrecision()));
break;
case MAP:
Map<String, Object> keyType;
Map<String, Object> valueType;
if (from instanceof ArbitraryMapType) {
keyType = ImmutableMap.of("primitive_type", "DT_ANY");
valueType = ImmutableMap.of("primitive_type", "DT_ANY");
} else {
keyType = convert(from.getKeyType()).getYamlDesc();
valueType = convert(from.getValueType()).getYamlDesc();
}
yamlDesc =
ImmutableMap.of(
"map",
ImmutableMap.of("key_type", keyType, "value_type", valueType));
break;
case DECIMAL:
yamlDesc =
ImmutableMap.of(
"decimal",
ImmutableMap.of(
"precision", from.getPrecision(),
"scale", from.getScale()));
break;
default:
if (throwsOnFail) {
throw new UnsupportedOperationException(
"convert RelDataType ["
+ from
+ "] to GSDataTypeDesc is unsupported yet");
}
yamlDesc = ImmutableMap.of("primitive_type", "DT_ANY");
}
return new GSDataTypeDesc(yamlDesc);
}

Check notice on line 474 in interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java

View check run for this annotation

codefactor.io / CodeFactor

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/IrDataTypeConvertor.java#L357-L474

Complex Method
private @Nullable Integer getIntValue(Object valueMap, String key) {
if (valueMap instanceof Map) {
Object value = ((Map) valueMap).get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ fn encode_runtime_prop_val(prop_val: Property) -> Object {
},
},
},
Property::UInt(i) => Object::Primitive(Primitives::UInteger(i)),
Property::ULong(l) => Object::Primitive(Primitives::ULong(l)),
Property::Date32(i) => Object::DateFormat(DateTimeFormats::from_date32_dur(i).unwrap()),
Property::Time32(i) => Object::DateFormat(DateTimeFormats::from_time32(i).unwrap()),
Property::Timestamp(l) => Object::DateFormat(DateTimeFormats::from_timestamp_millis(l).unwrap()),
_ => unimplemented!(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,10 @@ fn encode_store_prop_val(prop_val: Object) -> Property {
Object::Primitive(p) => match p {
Primitives::Byte(b) => Property::Char(b as u8),
Primitives::Integer(i) => Property::Int(i),
// will support u32 in groot soon.
Primitives::UInteger(i) => Property::Int(i as i32),
Primitives::UInteger(i) => Property::UInt(i),
Primitives::Long(i) => Property::Long(i),
// will support u64 in groot soon.
Primitives::ULong(i) => Property::Long(i as i64),
Primitives::ULLong(i) => Property::Long(i as i64),
Primitives::ULong(i) => Property::ULong(i),
Primitives::ULLong(i) => Property::ULong(i as u64),
Primitives::Float(f) => Property::Float(f),
Primitives::Double(f) => Property::Double(f),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ impl GraphPartitionManager for GlobalGraph {
Property::Unknown => {
unimplemented!()
}
Property::UInt(i) => {
data.write_u32::<BigEndian>(*i).unwrap();
}
Property::ULong(l) => {
data.write_u64::<BigEndian>(*l).unwrap();
}
Property::Date32(i) => {
data.write_i32::<BigEndian>(*i).unwrap();
}
Property::Time32(i) => {
data.write_i32::<BigEndian>(*i).unwrap();
}
Property::Timestamp(l) => {
data.write_i64::<BigEndian>(*l).unwrap();
}
}
data
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ impl Schema for GlobalGraphSchema {
ValueType::FloatList => Some(DataType::ListFloat),
ValueType::DoubleList => Some(DataType::ListDouble),
ValueType::StringList => Some(DataType::ListString),
ValueType::UInt => Some(DataType::UInt),
ValueType::ULong => Some(DataType::ULong),
ValueType::Date32 => Some(DataType::Date32),
ValueType::Time32 => Some(DataType::Time32),
ValueType::Timestamp => Some(DataType::Timestamp),
ValueType::FixedChar(_) => todo!(),
ValueType::VarChar(_) => todo!(),
}
}

Expand Down
Loading
Loading