Search in sources :

Example 1 with TypeInfo

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();
}
Also used : TableValueConstructorTable(org.h2.table.TableValueConstructorTable) Expression(org.h2.expression.Expression) ExpressionColumn(org.h2.expression.ExpressionColumn) Column(org.h2.table.Column) Database(org.h2.engine.Database) ArrayList(java.util.ArrayList) TypeInfo(org.h2.value.TypeInfo) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 2 with TypeInfo

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);
    }
}
Also used : TypeInfo(org.h2.value.TypeInfo) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 3 with TypeInfo

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;
}
Also used : TypedValueExpression(org.h2.expression.TypedValueExpression) ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression) ExpressionColumn(org.h2.expression.ExpressionColumn) Column(org.h2.table.Column) Value(org.h2.value.Value) Parameter(org.h2.expression.Parameter) TypeInfo(org.h2.value.TypeInfo) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 4 with TypeInfo

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));
    }
}
Also used : TypedValueExpression(org.h2.expression.TypedValueExpression) ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression) ExpressionVisitor(org.h2.expression.ExpressionVisitor) TypeInfo(org.h2.value.TypeInfo) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 5 with TypeInfo

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));
}
Also used : ExpressionVisitor(org.h2.expression.ExpressionVisitor) TypeInfo(org.h2.value.TypeInfo) ExpressionColumn(org.h2.expression.ExpressionColumn)

Aggregations

TypeInfo (org.h2.value.TypeInfo)127 ValueBigint (org.h2.value.ValueBigint)34 Value (org.h2.value.Value)33 TypeInfo (org.gridgain.internal.h2.value.TypeInfo)25 DbException (org.h2.message.DbException)22 Expression (org.h2.expression.Expression)19 ArrayList (java.util.ArrayList)18 Schema (org.h2.schema.Schema)18 ExpressionColumn (org.h2.expression.ExpressionColumn)17 Column (org.h2.table.Column)16 ValueSmallint (org.h2.value.ValueSmallint)16 Constraint (org.h2.constraint.Constraint)14 TypedValueExpression (org.h2.expression.TypedValueExpression)14 ValueExpression (org.h2.expression.ValueExpression)14 Column (org.gridgain.internal.h2.table.Column)12 Domain (org.h2.schema.Domain)12 FunctionAlias (org.h2.schema.FunctionAlias)12 JavaMethod (org.h2.schema.FunctionAlias.JavaMethod)12 AlterDomainAddConstraint (org.h2.command.ddl.AlterDomainAddConstraint)10 Database (org.h2.engine.Database)10