case OpTypes.LIKE_ARG : {
boolean hasEscape = nodes[RIGHT] != null;
int escapeChar = Integer.MAX_VALUE;
if (dataType.isBinaryType()) {
BinaryData left =
(BinaryData) nodes[LEFT].getValue(session);
if (left == null) {
return null;
}
if (hasEscape) {
BinaryData right =
(BinaryData) nodes[RIGHT].getValue(session);
if (right == null) {
return null;
}
if (right.length(session) != 1) {
throw Error.error(ErrorCode.X_2200D);
}
escapeChar = right.getBytes()[0];
}
byte[] array = left.getBytes();
byte[] newArray = new byte[array.length];
boolean wasEscape = false;
int escapeCount = 0;
int i = 0;
int j = 0;
for (; i < array.length; i++) {
if (array[i] == escapeChar) {
if (wasEscape) {
escapeCount++;
newArray[j++] = array[i];
wasEscape = false;
continue;
}
wasEscape = true;
if (i == array.length - 1) {
throw Error.error(ErrorCode.X_22025);
}
continue;
}
if (array[i] == '_' || array[i] == '%') {
if (wasEscape) {
escapeCount++;
newArray[j++] = array[i];
wasEscape = false;
continue;
}
break;
}
if (wasEscape) {
throw Error.error(ErrorCode.X_22025);
}
newArray[j++] = array[i];
}
newArray =
(byte[]) ArrayUtil.resizeArrayIfDifferent(newArray, j);
return new BinaryData(newArray, false);
} else {
String left =
(String) Type.SQL_VARCHAR.convertToType(session,
nodes[LEFT].getValue(session),
nodes[LEFT].getDataType());
if (left == null) {
return null;
}
if (hasEscape) {
String right =
(String) Type.SQL_VARCHAR.convertToType(session,
nodes[RIGHT].getValue(session),
nodes[RIGHT].getDataType());
if (right == null) {
return null;
}
if (right.length() != 1) {
throw Error.error(ErrorCode.X_22019);
}
escapeChar = right.getBytes()[0];
}
char[] array = left.toCharArray();
char[] newArray = new char[array.length];
boolean wasEscape = false;
int escapeCount = 0;
int i = 0;
int j = 0;
for (; i < array.length; i++) {
if (array[i] == escapeChar) {
if (wasEscape) {
escapeCount++;
newArray[j++] = array[i];
wasEscape = false;
continue;
}
wasEscape = true;
if (i == array.length - 1) {
throw Error.error(ErrorCode.X_22025);
}
continue;
}
if (array[i] == '_' || array[i] == '%') {
if (wasEscape) {
escapeCount++;
newArray[j++] = array[i];
wasEscape = false;
continue;
}
break;
}
if (wasEscape) {
throw Error.error(ErrorCode.X_22025);
}
newArray[j++] = array[i];
}
return new String(newArray, 0, j);
}
}
case OpTypes.SIMPLE_COLUMN : {
Object value =
session.sessionContext.rangeIterators[rangePosition]
.getCurrent(columnIndex);
return value;
}
case OpTypes.ORDER_BY :
return nodes[LEFT].getValue(session);
case OpTypes.PREFIX : {
if (nodes[LEFT].dataType.isCharacterType()) {
Object value = nodes[RIGHT].getValue(session);
if (value == null) {
return null;
}
CharacterType type = (CharacterType) nodes[RIGHT].dataType;
long length =
((CharacterType) nodes[RIGHT].dataType).size(session,
value);
type = (CharacterType) nodes[LEFT].dataType;
value = nodes[LEFT].getValue(session);
if (value == null) {
return null;
}
return type.substring(session, value, 0, length, true,
false);
} else {
BinaryData value =
(BinaryData) nodes[RIGHT].getValue(session);
if (value == null) {
return null;
}
long length = value.length(session);
BinaryType type = (BinaryType) nodes[LEFT].dataType;
value = (BinaryData) nodes[LEFT].getValue(session);
if (value == null) {