use of org.gridgain.internal.h2.value.TypeInfo in project SpringStudy by myounghaklee.
the class TableValueConstructor method createTable.
private void createTable() {
int rowCount = rows.size();
ArrayList<Expression> row = rows.get(0);
int columnCount = row.size();
TypeInfo[] types = new TypeInfo[columnCount];
for (int c = 0; c < columnCount; c++) {
Expression e = row.get(c).optimize(session);
row.set(c, e);
TypeInfo type = e.getType();
if (type.getValueType() == Value.UNKNOWN) {
type = TypeInfo.TYPE_VARCHAR;
}
types[c] = type;
}
for (int r = 1; r < rowCount; r++) {
row = rows.get(r);
for (int c = 0; c < columnCount; c++) {
Expression e = row.get(c).optimize(session);
row.set(c, e);
types[c] = TypeInfo.getHigherType(types[c], e.getType());
}
}
Column[] columns = new Column[columnCount];
for (int c = 0; c < columnCount; ) {
TypeInfo type = types[c];
columns[c] = new Column("C" + ++c, type);
}
Database database = session.getDatabase();
ArrayList<Expression> expressions = new ArrayList<>(columnCount);
for (int i = 0; i < columnCount; i++) {
expressions.add(new ExpressionColumn(database, null, null, columns[i].getName()));
}
this.expressions = expressions;
table = new TableValueConstructorTable(session.getDatabase().getMainSchema(), session, columns, rows);
columnResolver = new TableValueColumnResolver();
}
use of org.gridgain.internal.h2.value.TypeInfo in project SpringStudy by myounghaklee.
the class Comparison method createIndexConditions.
static void createIndexConditions(TableFilter filter, Expression left, Expression right, int compareType) {
if (!filter.getTable().isQueryComparable()) {
return;
}
ExpressionColumn l = null;
if (left instanceof ExpressionColumn) {
l = (ExpressionColumn) left;
if (filter != l.getTableFilter()) {
l = null;
}
}
ExpressionColumn r = null;
if (right instanceof ExpressionColumn) {
r = (ExpressionColumn) right;
if (filter != r.getTableFilter()) {
r = null;
}
}
// one side must be from the current filter
if ((l == null) == (r == null)) {
return;
}
if (l == null) {
if (!left.isEverything(ExpressionVisitor.getNotFromResolverVisitor(filter))) {
return;
}
} else {
// r == null
if (!right.isEverything(ExpressionVisitor.getNotFromResolverVisitor(filter))) {
return;
}
}
switch(compareType) {
case NOT_EQUAL:
case NOT_EQUAL_NULL_SAFE:
break;
case EQUAL:
case EQUAL_NULL_SAFE:
case BIGGER:
case BIGGER_EQUAL:
case SMALLER_EQUAL:
case SMALLER:
case SPATIAL_INTERSECTS:
if (l != null) {
TypeInfo colType = l.getType();
if (TypeInfo.haveSameOrdering(colType, TypeInfo.getHigherType(colType, right.getType()))) {
filter.addIndexCondition(IndexCondition.get(compareType, l, right));
}
} else {
@SuppressWarnings("null") TypeInfo colType = r.getType();
if (TypeInfo.haveSameOrdering(colType, TypeInfo.getHigherType(colType, left.getType()))) {
filter.addIndexCondition(IndexCondition.get(getReversedCompareType(compareType), r, left));
}
}
break;
default:
throw DbException.getInternalError("type=" + compareType);
}
}
use of org.gridgain.internal.h2.value.TypeInfo in project SpringStudy by myounghaklee.
the class Comparison method optimize.
@Override
public Expression optimize(SessionLocal session) {
left = left.optimize(session);
right = right.optimize(session);
check: {
TypeInfo leftType = left.getType(), rightType = right.getType();
if (session.getMode().numericWithBooleanComparison) {
switch(compareType) {
case EQUAL:
case NOT_EQUAL:
case EQUAL_NULL_SAFE:
case NOT_EQUAL_NULL_SAFE:
int lValueType = leftType.getValueType();
if (lValueType == Value.BOOLEAN) {
if (DataType.isNumericType(rightType.getValueType())) {
break check;
}
} else if (DataType.isNumericType(lValueType) && rightType.getValueType() == Value.BOOLEAN) {
break check;
}
}
}
TypeInfo.checkComparable(leftType, rightType);
}
if (whenOperand) {
return this;
}
if (right instanceof ExpressionColumn) {
if (left.isConstant() || left instanceof Parameter) {
Expression temp = left;
left = right;
right = temp;
compareType = getReversedCompareType(compareType);
}
}
if (left instanceof ExpressionColumn) {
if (right.isConstant()) {
Value r = right.getValue(session);
if (r == ValueNull.INSTANCE) {
if ((compareType & ~1) != EQUAL_NULL_SAFE) {
return TypedValueExpression.UNKNOWN;
}
}
TypeInfo colType = left.getType(), constType = r.getType();
int constValueType = constType.getValueType();
if (constValueType != colType.getValueType() || constValueType >= Value.ARRAY) {
TypeInfo resType = TypeInfo.getHigherType(colType, constType);
// once.
if (constValueType != resType.getValueType() || constValueType >= Value.ARRAY) {
Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType, session, column));
}
}
} else if (right instanceof Parameter) {
((Parameter) right).setColumn(((ExpressionColumn) left).getColumn());
}
}
if (left.isConstant() && right.isConstant()) {
return ValueExpression.getBoolean(getValue(session));
}
if (left.isNullConstant() || right.isNullConstant()) {
// a NULL constants
if ((compareType & ~1) != EQUAL_NULL_SAFE) {
return TypedValueExpression.UNKNOWN;
} else {
Expression e = left.isNullConstant() ? right : left;
int type = e.getType().getValueType();
if (type != Value.UNKNOWN && type != Value.ROW) {
return new NullPredicate(e, compareType == NOT_EQUAL_NULL_SAFE, false);
}
}
}
return this;
}
use of org.gridgain.internal.h2.value.TypeInfo in project SpringStudy by myounghaklee.
the class ConditionIn method createIndexConditions.
@Override
public void createIndexConditions(SessionLocal session, TableFilter filter) {
if (not || whenOperand || !(left instanceof ExpressionColumn)) {
return;
}
ExpressionColumn l = (ExpressionColumn) left;
if (filter != l.getTableFilter()) {
return;
}
if (session.getDatabase().getSettings().optimizeInList) {
ExpressionVisitor visitor = ExpressionVisitor.getNotFromResolverVisitor(filter);
TypeInfo colType = l.getType();
for (Expression e : valueList) {
if (!e.isEverything(visitor) || !TypeInfo.haveSameOrdering(colType, TypeInfo.getHigherType(colType, e.getType()))) {
return;
}
}
filter.addIndexCondition(IndexCondition.getInList(l, valueList));
}
}
use of org.gridgain.internal.h2.value.TypeInfo in project SpringStudy by myounghaklee.
the class ConditionInQuery method createIndexConditions.
@Override
public void createIndexConditions(SessionLocal session, TableFilter filter) {
if (!session.getDatabase().getSettings().optimizeInList) {
return;
}
if (not || compareType != Comparison.EQUAL) {
return;
}
if (query.getColumnCount() != 1) {
return;
}
if (!(left instanceof ExpressionColumn)) {
return;
}
TypeInfo colType = left.getType();
TypeInfo queryType = query.getExpressions().get(0).getType();
if (!TypeInfo.haveSameOrdering(colType, TypeInfo.getHigherType(colType, queryType))) {
return;
}
int leftType = colType.getValueType();
if (!DataType.hasTotalOrdering(leftType) && leftType != queryType.getValueType()) {
return;
}
ExpressionColumn l = (ExpressionColumn) left;
if (filter != l.getTableFilter()) {
return;
}
ExpressionVisitor visitor = ExpressionVisitor.getNotFromResolverVisitor(filter);
if (!query.isEverything(visitor)) {
return;
}
filter.addIndexCondition(IndexCondition.getInQuery(l, query));
}
Aggregations