use of io.ordinate.engine.function.BinarySequence in project Mycat2 by MyCATApache.
the class FooFunctionSink method copy.
@Override
public void copy(Function[] functions, Record inputRecord, int rowId, VectorSchemaRoot output) {
int columnId = 0;
for (Function function : functions) {
FieldVector vector = output.getVector(columnId);
switch(function.getType()) {
case BOOLEAN_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
BitVector bitVector = (BitVector) vector;
if (isNull) {
bitVector.setNull(rowId);
} else {
bitVector.set(rowId, value);
}
break;
}
case INT8_TYPE:
{
int value = function.getByte(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case UINT8_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case CHAR_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case INT16_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case UINT16_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case INT32_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case UINT32_TYPE:
{
int value = function.getInt(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case INT64_TYPE:
{
long value = function.getLong(inputRecord);
boolean isNull = function.isNull(inputRecord);
BigIntVector bigIntVector = (BigIntVector) output.getVector(columnId);
setInt(rowId, output, columnId, value, isNull);
break;
}
case UINT64_TYPE:
{
long value = function.getLong(inputRecord);
boolean isNull = function.isNull(inputRecord);
setInt(rowId, output, columnId, value, isNull);
break;
}
case FLOAT_TYPE:
{
float value = function.getFloat(inputRecord);
boolean isNull = function.isNull(inputRecord);
Float4Vector float4Vector = (Float4Vector) output.getVector(columnId);
if (isNull) {
float4Vector.setNull(rowId);
} else {
float4Vector.set(rowId, value);
}
break;
}
case DOUBLE_TYPE:
{
double value = function.getDouble(inputRecord);
boolean isNull = function.isNull(inputRecord);
Float8Vector float8Vector = (Float8Vector) output.getVector(columnId);
if (isNull) {
float8Vector.setNull(rowId);
} else {
float8Vector.set(rowId, value);
}
break;
}
case SYMBOL_TYPE:
case STRING_TYPE:
{
CharSequence value = function.getString(inputRecord);
boolean isNull = function.isNull(inputRecord);
VarCharVector varCharVector = (VarCharVector) output.getVector(columnId);
if (isNull) {
varCharVector.setNull(rowId);
} else {
varCharVector.set(rowId, new Text(value.toString()));
}
break;
}
case BINARY_TYPE:
{
BinarySequence value = function.getBinary(inputRecord);
boolean isNull = function.isNull(inputRecord);
VarBinaryVector varBinaryVector = (VarBinaryVector) output.getVector(columnId);
if (isNull) {
varBinaryVector.setNull(rowId);
} else {
varBinaryVector.set(rowId, value.getBytes());
}
break;
}
case TIME_MILLI_TYPE:
{
long value = function.getTime(inputRecord);
boolean isNull = function.isNull(inputRecord);
TimeMilliVector timeMilliVector = (TimeMilliVector) output.getVector(columnId);
if (isNull) {
timeMilliVector.setNull(rowId);
} else {
timeMilliVector.set(rowId, (int) value);
}
break;
}
case DATE_TYPE:
{
long value = function.getDate(inputRecord);
boolean isNull = function.isNull(inputRecord);
DateMilliVector dateMilliVector = (DateMilliVector) output.getVector(columnId);
if (isNull) {
dateMilliVector.setNull(rowId);
} else {
dateMilliVector.set(rowId, value);
}
break;
}
case DATETIME_MILLI_TYPE:
{
long value = function.getDatetime(inputRecord);
boolean isNull = function.isNull(inputRecord);
TimeStampVector dateMilliVector = (TimeStampVector) output.getVector(columnId);
if (isNull) {
dateMilliVector.setNull(rowId);
} else {
dateMilliVector.set(rowId, value);
}
break;
}
case OBJECT_TYPE:
case NULL_TYPE:
throw new UnsupportedOperationException();
}
columnId++;
}
}
use of io.ordinate.engine.function.BinarySequence 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.function.BinarySequence in project Mycat2 by MyCATApache.
the class NLJoinPlan method createRecord.
private Record createRecord(VectorSchemaRoot leftInput, int leftIndex, VectorSchemaRoot rightBatch, int rightIndex) {
int leftCount = leftInput.getFieldVectors().size();
IntUnaryOperator function = columnIndex -> {
if (columnIndex < leftCount) {
return leftIndex;
} else {
return rightIndex;
}
};
return new Record() {
boolean isNull;
@Override
public void setPosition(int value) {
}
private int getPosition(int columnIndex) {
return function.applyAsInt(columnIndex);
}
private <T extends FieldVector> T getFieldVector(int columnIndex) {
FieldVector vector;
if (columnIndex < leftCount) {
vector = leftInput.getVector(columnIndex);
} else {
vector = rightBatch.getVector(columnIndex - leftCount);
}
return (T) vector;
}
@Override
public int getInt(int columnIndex) {
IntVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public long getLong(int columnIndex) {
BigIntVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public byte getByte(int columnIndex) {
TinyIntVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public short getShort(int columnIndex) {
SmallIntVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public BinarySequence getBinary(int columnIndex) {
VarBinaryVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return null;
} else {
isNull = false;
return BinarySequence.of(vector.get(position));
}
}
@Override
public char getChar(int columnIndex) {
SmallIntVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return (char) vector.get(position);
}
}
@Override
public long getDate(int columnIndex) {
DateMilliVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public long getDatetime(int columnIndex) {
TimeStampVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position) * 1000L;
}
}
@Override
public CharSequence getString(int columnIndex) {
VarCharVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return null;
} else {
isNull = false;
return new String(vector.get(position));
}
}
@Override
public CharSequence getSymbol(int columnIndex) {
return getString(columnIndex);
}
@Override
public float getFloat(int columnIndex) {
Float4Vector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public double getDouble(int columnIndex) {
Float8Vector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public long getTime(int columnIndex) {
TimeStampVector vector = getFieldVector(columnIndex);
int position = getPosition(columnIndex);
if (vector.isNull(position)) {
isNull = true;
return 0;
} else {
isNull = false;
return vector.get(position);
}
}
@Override
public boolean isNull(int columnIndex) {
return false;
}
@Override
public short getUInt16(int columnIndex) {
return 0;
}
@Override
public long getUInt64(int columnIndex) {
return 0;
}
@Override
public Object getObject(int columnIndex) {
return null;
}
@Override
public int getUInt32(int i) {
return 0;
}
@Override
public String toString() {
int columnCount = leftInput.getSchema().getFields().size() + rightBatch.getSchema().getFields().size();
ArrayList arrayList = new ArrayList();
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
FieldVector vector = getFieldVector(columnIndex);
Object object = vector.getObject(function.applyAsInt(columnIndex));
arrayList.add(object);
}
return arrayList.toString();
}
};
}
use of io.ordinate.engine.function.BinarySequence in project Mycat2 by MyCATApache.
the class IfNullFunctionFactory method newInstance.
@Override
public Function newInstance(List<Function> args, EngineConfiguration configuration) {
return new Function() {
Function left;
Function right;
boolean isNull;
@Override
public InnerType getType() {
return left.getType();
}
@Override
public List<Function> getArgs() {
return args;
}
@Override
public BinarySequence getBinary(Record rec) {
isNull = false;
BinarySequence binary = left.getBinary(rec);
if (!left.isNull(rec)) {
return binary;
}
binary = right.getBinary(rec);
if (!right.isNull(rec)) {
return binary;
}
isNull = true;
return null;
}
@Override
public byte getByte(Record rec) {
isNull = false;
byte aByte = left.getByte(rec);
if (!left.isNull(rec)) {
return aByte;
}
aByte = right.getByte(rec);
if (!right.isNull(rec)) {
return aByte;
}
isNull = true;
return 0;
}
@Override
public char getChar(Record rec) {
isNull = false;
char aChar = left.getChar(rec);
if (!left.isNull(rec)) {
return aChar;
}
aChar = right.getChar(rec);
if (!right.isNull(rec)) {
return aChar;
}
isNull = true;
return 0;
}
@Override
public long getDate(Record rec) {
isNull = false;
long date = left.getDate(rec);
if (!left.isNull(rec)) {
return date;
}
date = right.getDate(rec);
if (!right.isNull(rec)) {
return date;
}
isNull = true;
return 0;
}
@Override
public double getDouble(Record rec) {
isNull = false;
double aDouble = left.getDouble(rec);
if (!left.isNull(rec)) {
return aDouble;
}
aDouble = right.getDouble(rec);
if (!right.isNull(rec)) {
return aDouble;
}
isNull = true;
return 0;
}
@Override
public float getFloat(Record rec) {
isNull = false;
float aFloat = left.getFloat(rec);
if (!left.isNull(rec)) {
return aFloat;
}
aFloat = right.getFloat(rec);
if (!right.isNull(rec)) {
return aFloat;
}
isNull = true;
return 0;
}
@Override
public int getInt(Record rec) {
isNull = false;
int anInt = left.getInt(rec);
if (!left.isNull(rec)) {
return anInt;
}
anInt = right.getInt(rec);
if (!right.isNull(rec)) {
return anInt;
}
isNull = true;
return 0;
}
@Override
public long getLong(Record rec) {
isNull = false;
long aLong = left.getLong(rec);
if (!left.isNull(rec)) {
return aLong;
}
aLong = right.getLong(rec);
if (!right.isNull(rec)) {
return aLong;
}
isNull = true;
return 0;
}
@Override
public short getShort(Record rec) {
isNull = false;
short aLong = left.getShort(rec);
if (!left.isNull(rec)) {
return aLong;
}
aLong = right.getShort(rec);
if (!right.isNull(rec)) {
return aLong;
}
isNull = true;
return 0;
}
@Override
public CharSequence getString(Record rec) {
isNull = false;
CharSequence charSequence = left.getString(rec);
if (!left.isNull(rec)) {
return charSequence;
}
charSequence = right.getString(rec);
if (!right.isNull(rec)) {
return charSequence;
}
isNull = true;
return null;
}
@Override
public long getDatetime(Record rec) {
isNull = false;
long datetime = left.getDatetime(rec);
if (!left.isNull(rec)) {
return datetime;
}
datetime = right.getDatetime(rec);
if (!right.isNull(rec)) {
return datetime;
}
isNull = true;
return 0;
}
@Override
public long getTime(Record rec) {
isNull = false;
long time = left.getTime(rec);
if (!left.isNull(rec)) {
return time;
}
time = right.getTime(rec);
if (!right.isNull(rec)) {
return time;
}
isNull = true;
return 0;
}
@Override
public CharSequence getSymbol(Record rec) {
isNull = false;
CharSequence symbol = left.getSymbol(rec);
if (!left.isNull(rec)) {
return symbol;
}
symbol = right.getSymbol(rec);
if (!right.isNull(rec)) {
return symbol;
}
isNull = true;
return null;
}
@Override
public boolean isNull(Record rec) {
return isNull;
}
};
}
use of io.ordinate.engine.function.BinarySequence in project Mycat2 by MyCATApache.
the class ExprVectorExpression method eval.
@Override
public void eval(VectorContext ctx) {
FieldVector outputVector = ctx.getOutputVector();
int nullCount = outputVector.getNullCount();
int rowCount = ctx.getRowCount();
boolean nullable = function.isNullableConstant();
Record record = function.generateSink(ctx);
switch(function.getType()) {
case BOOLEAN_TYPE:
{
BitVector bitVector = (BitVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
int value = function.getInt(record);
boolean isNull = function.isNull(record);
if (isNull) {
bitVector.setNull(i);
} else {
bitVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
int bool = function.getInt(record);
bitVector.set(i, bool);
}
}
break;
}
case INT8_TYPE:
break;
case INT16_TYPE:
break;
case INT32_TYPE:
{
IntVector valueVector = (IntVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
int value = function.getInt(record);
if (function.isNull(record)) {
valueVector.setNull(i);
} else {
valueVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
int value = function.getInt(record);
valueVector.set(i, value);
}
}
break;
}
case INT64_TYPE:
{
BigIntVector valueVector = (BigIntVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getLong(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getLong(record);
valueVector.set(i, value);
}
}
break;
}
case FLOAT_TYPE:
{
Float4Vector valueVector = (Float4Vector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
float value = function.getFloat(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
float value = function.getFloat(record);
valueVector.set(i, value);
}
}
break;
}
case DOUBLE_TYPE:
{
Float8Vector valueVector = (Float8Vector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
double value = function.getDouble(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
double value = function.getDouble(record);
valueVector.set(i, value);
}
}
break;
}
case STRING_TYPE:
{
VarCharVector valueVector = (VarCharVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
CharSequence value = function.getString(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.setSafe(i, (value.toString().getBytes()));
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
CharSequence value = function.getString(record);
valueVector.set(i, value.toString().getBytes());
}
}
break;
}
case BINARY_TYPE:
{
VarBinaryVector valueVector = (VarBinaryVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
BinarySequence value = function.getBinary(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.setSafe(i, (value.getBytes()));
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
BinarySequence value = function.getBinary(record);
valueVector.set(i, value.getBytes());
}
}
break;
}
case UINT8_TYPE:
break;
case UINT16_TYPE:
break;
case UINT32_TYPE:
break;
case UINT64_TYPE:
break;
case TIME_MILLI_TYPE:
{
TimeMilliVector valueVector = (TimeMilliVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
int value = (int) function.getTime(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.set(i, (value));
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
int value = (int) function.getTime(record);
valueVector.set(i, value);
}
}
break;
}
case DATE_TYPE:
{
DateMilliVector valueVector = (DateMilliVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getDate(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.set(i, value);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getDate(record);
valueVector.set(i, value);
}
}
break;
}
case DATETIME_MILLI_TYPE:
{
TimeStampMilliVector valueVector = (TimeStampMilliVector) outputVector;
if (function.isNullableConstant()) {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getDatetime(record);
boolean isNull = function.isNull(record);
if (isNull) {
valueVector.setNull(i);
} else {
valueVector.setSafe(i, (value));
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
long value = function.getDatetime(record);
valueVector.set(i, value);
}
}
break;
}
}
}
Aggregations