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 @@ public enum DataType {
BYTES_LIST(15),
DATE(16), // represent DATE32
TIME32(17),
TIMESTAMP(18);
TIMESTAMP(18),
UINT(19),
ULONG(20);

private final byte type;

Expand Down Expand Up @@ -85,6 +87,10 @@ public static DataType parseProto(DataTypePb pb) {
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 + "]");
}
Expand Down Expand Up @@ -139,6 +145,10 @@ public DataTypePb toProto() {
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 + "]");
}
Expand Down
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 Down Expand Up @@ -54,14 +61,24 @@ private static Object stringToObj(DataType dataType, Object val) {
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);
}
Expand All @@ -78,6 +95,65 @@ private static Object stringToObj(DataType dataType, Object val) {
}
}

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()
+ "].",
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 @@ public static byte[] objectToBytes(DataType dataType, Object valObject) {
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 @@ public static byte[] objectToBytes(DataType dataType, Object valObject) {
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 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 Down Expand Up @@ -77,9 +87,17 @@ public RelDataType convert(DataType from) {
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);
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