use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class CodeGenRecordSinkFactoryImpl method generateCopyRecordBody.
public static BlockStatement generateCopyRecordBody(IntInnerType[] types) {
ArrayList<Statement> setterStatements = new ArrayList<>(types.length);
for (int varIndex = 0; varIndex < types.length; varIndex++) {
IntInnerType intPair = types[varIndex];
int columnIndex = intPair.index;
InnerType type = intPair.type;
ConstantExpression index = Expressions.constant(columnIndex);
MethodCallExpression isNullCondition = Expressions.call(from, "isNull", index);
setterStatements.add(Expressions.ifThenElse(isNullCondition, Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "copyNullType", from, to, index)), Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "copy" + type.name(), from, to, index))));
}
return Expressions.block(setterStatements);
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class RecordSinkFactoryImpl method buildEqualComparator.
@Override
public RecordComparator buildEqualComparator(InnerType[] types) {
return new RecordComparator() {
Record leftRecord;
Record rightRecord;
@Override
public int compare(Record record) {
return compare(leftRecord, record);
}
@Override
public int compare() {
return compare(leftRecord, rightRecord);
}
@Override
public void setLeft(Record record) {
this.leftRecord = record;
}
@Override
public void setRight(Record record) {
this.rightRecord = record;
}
public int compare(Record left, Record right) {
int length = types.length;
int res = 0;
for (int columnIndex = 0; columnIndex < length; columnIndex++) {
InnerType type = types[columnIndex];
switch(type) {
case BOOLEAN_TYPE:
{
res = Boolean.compare(left.getBooleanType(columnIndex), right.getBooleanType(columnIndex));
break;
}
case INT8_TYPE:
{
res = Integer.compare(left.getInt(columnIndex), right.getInt(columnIndex));
break;
}
case INT16_TYPE:
{
res = Short.compare(left.getShort(columnIndex), right.getShort(columnIndex));
break;
}
case CHAR_TYPE:
{
res = Character.compare(left.getCharType(columnIndex), right.getChar(columnIndex));
break;
}
case INT32_TYPE:
{
res = Integer.compare(left.getInt32Type(columnIndex), right.getInt32Type(columnIndex));
break;
}
case INT64_TYPE:
{
res = Long.compare(left.getInt64Type(columnIndex), right.getInt64Type(columnIndex));
break;
}
case FLOAT_TYPE:
{
res = Float.compare(left.getFloatType(columnIndex), right.getFloatType(columnIndex));
break;
}
case DOUBLE_TYPE:
{
res = Double.compare(left.getDoubleType(columnIndex), right.getDoubleType(columnIndex));
break;
}
case STRING_TYPE:
{
res = left.getString(columnIndex).toString().compareTo(right.getString(columnIndex).toString());
break;
}
case BINARY_TYPE:
{
BinarySequence leftBinary = left.getBinary(columnIndex);
BinarySequence rightBinary = right.getBinary(columnIndex);
res = leftBinary.compareTo(rightBinary);
break;
}
case UINT8_TYPE:
{
int l = Byte.toUnsignedInt(left.getUInt8Type(columnIndex));
int r = Byte.toUnsignedInt(right.getUInt8Type(columnIndex));
res = Integer.compare(l, r);
break;
}
case UINT16_TYPE:
{
int l = Short.toUnsignedInt(left.getUInt16(columnIndex));
int r = Short.toUnsignedInt(right.getUInt16(columnIndex));
res = Integer.compare(l, r);
break;
}
case UINT32_TYPE:
{
long l = Integer.toUnsignedLong(left.getUInt32(columnIndex));
long r = Integer.toUnsignedLong(right.getUInt32(columnIndex));
res = Long.compare(l, r);
break;
}
case UINT64_TYPE:
{
res = UnsignedLong.fromLongBits(left.getUInt64(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getUInt64(columnIndex)));
break;
}
case TIME_MILLI_TYPE:
{
res = UnsignedLong.fromLongBits(left.getTime(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getTime(columnIndex)));
break;
}
case DATE_TYPE:
{
res = UnsignedLong.fromLongBits(left.getDate(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getDate(columnIndex)));
break;
}
case DATETIME_MILLI_TYPE:
{
res = UnsignedLong.fromLongBits(left.getDatetime(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getDatetime(columnIndex)));
break;
}
case SYMBOL_TYPE:
{
res = left.getSymbol(columnIndex).toString().compareTo((right.getSymbol(columnIndex)).toString());
break;
}
case OBJECT_TYPE:
case NULL_TYPE:
default:
throw new IllegalArgumentException();
}
if (res == 0) {
} else {
return res;
}
}
return 0;
}
};
}
use of io.ordinate.engine.schema.InnerType in project Mycat2 by MyCATApache.
the class ResultWriterUtil method resultSetColumnToVectorRowSchema.
public static Schema resultSetColumnToVectorRowSchema(MycatRowMetaData mycatRowMetaData) {
int columnCount = mycatRowMetaData.getColumnCount();
ImmutableList.Builder<Field> builder = ImmutableList.builder();
for (int i = 0; i < columnCount; i++) {
String columnName = mycatRowMetaData.getColumnName(i);
int columnType = mycatRowMetaData.getColumnType(i);
boolean signed = mycatRowMetaData.isSigned(i);
boolean nullable = mycatRowMetaData.isNullable(i);
InnerType innerType = InnerType.fromJdbc(columnType);
if (!signed) {
innerType = innerType.toUnsigned();
}
Field field = FieldBuilder.of(columnName, innerType.getArrowType(), nullable).toArrow();
builder.add(field);
}
return new org.apache.arrow.vector.types.pojo.Schema(builder.build());
}
Aggregations