if (nodes[0] == null) {
UUID uuid = java.util.UUID.randomUUID();
long hi = uuid.getMostSignificantBits();
long lo = uuid.getLeastSignificantBits();
return new BinaryData(ArrayUtil.toByteArray(hi, lo),
false);
} else {
if (data[0] == null) {
return null;
}
if (dataType.isBinaryType()) {
return new BinaryData(
StringConverter.toBinaryUUID((String) data[0]),
false);
} else {
return StringConverter.toStringUUID(
((BinaryData) data[0]).getBytes());
}
}
}
case FUNC_UNIX_MILLIS : {
TimestampData ts;
if (nodes[0] == null) {
ts = session.getCurrentTimestamp(true);
} else {
if (data[0] == null) {
return null;
}
ts = (TimestampData) data[0];
}
long millis = ts.getSeconds() * 1000 + ts.getNanos() / 1000000;
return Long.valueOf(millis);
}
case FUNC_UNIX_TIMESTAMP : {
TimestampData ts;
if (nodes[0] == null) {
ts = session.getCurrentTimestamp(true);
} else {
if (data[0] == null) {
return null;
}
ts = (TimestampData) data[0];
}
return Long.valueOf(ts.getSeconds());
}
case FUNC_ACOS : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.acos(d));
}
case FUNC_ASIN : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.asin(d));
}
case FUNC_ATAN : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.atan(d));
}
case FUNC_COS : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.cos(d));
}
case FUNC_COT : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
double c = 1.0 / java.lang.Math.tan(d);
return new Double(c);
}
case FUNC_DEGREES : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.toDegrees(d));
}
case FUNC_SIN : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.sin(d));
}
case FUNC_TAN : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.tan(d));
}
case FUNC_LOG10 : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.log10(d));
}
case FUNC_RADIANS : {
if (data[0] == null) {
return null;
}
double d = NumberType.toDouble(data[0]);
return new Double(java.lang.Math.toRadians(d));
}
//
case FUNC_SIGN : {
if (data[0] == null) {
return null;
}
int val =
((NumberType) nodes[0].dataType).compareToZero(data[0]);
return ValuePool.getInt(val);
}
case FUNC_ATAN2 : {
if (data[0] == null) {
return null;
}
double a = NumberType.toDouble(data[0]);
double b = NumberType.toDouble(data[1]);
return new Double(java.lang.Math.atan2(a, b));
}
case FUNC_ASCII : {
String arg;
if (data[0] == null) {
return null;
}
if (nodes[0].dataType.isLobType()) {
arg = ((ClobData) data[0]).getSubString(session, 0, 1);
} else {
arg = (String) data[0];
}
if (arg.length() == 0) {
return null;
}
return ValuePool.getInt(arg.charAt(0));
}
case FUNC_CHAR :
if (data[0] == null) {
return null;
}
data[0] = Type.SQL_INTEGER.convertToType(session, data[0],
nodes[0].getDataType());
int arg = ((Number) data[0]).intValue();
if (Character.isValidCodePoint(arg)
&& Character.isValidCodePoint((char) arg)) {
return String.valueOf((char) arg);
}
throw Error.error(ErrorCode.X_22511);
case FUNC_ROUNDMAGIC : {
int offset = 0;
if (data[0] == null) {
return null;
}
if (nodes.length > 1) {
if (data[1] == null) {
return null;
}
offset = ((Number) data[1]).intValue();
}
return ((NumberType) dataType).round(data[0], offset);
}
case FUNC_SOUNDEX : {
if (data[0] == null) {
return null;
}
String s = (String) data[0];
return new String(soundex(s), 0, 4);
}
case FUNC_BITAND :
case FUNC_BITANDNOT :
case FUNC_BITNOT :
case FUNC_BITOR :
case FUNC_BITXOR : {
for (int i = 0; i < data.length; i++) {
if (data[i] == null) {
return null;
}
}
if (dataType.isNumberType()) {
long v = 0;
long a;
long b = 0;
data[0] = Type.SQL_BIGINT.convertToType(session, data[0],
nodes[0].getDataType());
a = ((Number) data[0]).longValue();
if (funcType != FUNC_BITNOT) {
data[1] = Type.SQL_BIGINT.convertToType(session,
data[1], nodes[1].getDataType());
b = ((Number) data[1]).longValue();
}
switch (funcType) {
case FUNC_BITAND :
v = a & b;
break;
case FUNC_BITANDNOT :
v = a & ~b;
break;
case FUNC_BITNOT :
v = ~a;
break;
case FUNC_BITOR :
v = a | b;
break;
case FUNC_BITXOR :
v = a ^ b;
break;
}
switch (dataType.typeCode) {
case Types.SQL_NUMERIC :
case Types.SQL_DECIMAL :
return BigDecimal.valueOf(v);
case Types.SQL_BIGINT :
return ValuePool.getLong(v);
case Types.SQL_INTEGER :
case Types.SQL_SMALLINT :
case Types.TINYINT :
return ValuePool.getInt((int) v);
default :
throw Error.error(ErrorCode.X_42561);
}
} else {
byte[] a = ((BinaryData) data[0]).getBytes();
byte[] b = null;
byte[] v;
if (funcType != FUNC_BITNOT) {
b = ((BinaryData) data[1]).getBytes();
}
switch (funcType) {
case FUNC_BITAND :
v = BitMap.and(a, b);
break;
case FUNC_BITANDNOT :
b = BitMap.not(b);
v = BitMap.and(a, b);
break;
case FUNC_BITNOT :
v = BitMap.not(a);
break;
case FUNC_BITOR :
v = BitMap.or(a, b);
break;
case FUNC_BITXOR :
v = BitMap.xor(a, b);
break;
default :
throw Error.error(ErrorCode.X_42561);
}
return new BinaryData(v, dataType.precision);
}
}
case FUNC_DIFFERENCE : {
for (int i = 0; i < data.length; i++) {
if (data[i] == null) {