Search in sources :

Example 41 with TypeId

use of org.apache.derby.iapi.types.TypeId in project derby by apache.

the class DB2LengthOperatorNode method bindExpression.

/**
 * Bind this operator
 *
 * @param fromList			The query's FROM list
 * @param subqueryList		The subquery list being built as we find SubqueryNodes
 * @param aggregates    The aggregate list being built as we find AggregateNodes
 *
 * @return	The new top of the expression tree.
 *
 * @exception StandardException		Thrown on error
 */
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException {
    bindOperand(fromList, subqueryList, aggregates);
    // This operator is not allowed on XML types.
    TypeId operandType = operand.getTypeId();
    if (operandType.isXMLTypeId()) {
        throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, getOperatorString(), operandType.getSQLTypeName());
    }
    setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.INTEGER), operand.getTypeServices().isNullable()));
    return this;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 42 with TypeId

use of org.apache.derby.iapi.types.TypeId in project derby by apache.

the class SystemColumnImpl method getJavaColumn.

/**
 * Create a system column for a java column.
 *
 * @param name
 *            Name of the column.
 * @param javaClassName
 * @param nullability
 *            Nullability of the column.
 * @return Object representing the column.
 */
static SystemColumn getJavaColumn(String name, String javaClassName, boolean nullability) throws StandardException {
    TypeId typeId = TypeId.getUserDefinedTypeId(javaClassName);
    DataTypeDescriptor dtd = new DataTypeDescriptor(typeId, nullability);
    return new SystemColumnImpl(name, dtd);
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 43 with TypeId

use of org.apache.derby.iapi.types.TypeId in project derby by apache.

the class BinaryRelationalOperatorNode method booleanSelectivity.

/**
 * Return 50% if this is a comparison with a boolean column, a negative
 * selectivity otherwise.
 */
protected double booleanSelectivity(Optimizable optTable) throws StandardException {
    TypeId typeId = null;
    double retval = -1.0d;
    int columnSide;
    columnSide = columnOnOneSide(optTable);
    if (columnSide == LEFT)
        typeId = leftOperand.getTypeId();
    else if (columnSide == RIGHT)
        typeId = rightOperand.getTypeId();
    if (typeId != null && (typeId.getJDBCTypeId() == Types.BIT || typeId.getJDBCTypeId() == Types.BOOLEAN))
        retval = 0.5d;
    return retval;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId)

Example 44 with TypeId

use of org.apache.derby.iapi.types.TypeId in project derby by apache.

the class BinaryComparisonOperatorNode method bindExpression.

/**
 * Bind this comparison operator.  All that has to be done for binding
 * a comparison operator is to bind the operands, check the compatibility
 * of the types, and set the result type to SQLBoolean.
 *
 * @param fromList			The query's FROM list
 * @param subqueryList		The subquery list being built as we find SubqueryNodes
 * @param aggregates        The aggregate list being built as we find AggregateNodes
 *
 * @return	The new top of the expression tree.
 *
 * @exception StandardException		Thrown on error
 */
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException {
    super.bindExpression(fromList, subqueryList, aggregates);
    TypeId leftTypeId = leftOperand.getTypeId();
    TypeId rightTypeId = rightOperand.getTypeId();
    /*
		 * If we are comparing a non-string with a string type, then we
		 * must prevent the non-string value from being used to probe into
		 * an index on a string column. This is because the string types
		 * are all of low precedence, so the comparison rules of the non-string
		 * value are used, so it may not find values in a string index because
		 * it will be in the wrong order. So, cast the string value to its
		 * own type. This is easier than casting it to the non-string type,
		 * because we would have to figure out the right length to cast it to.
		 */
    if (!leftTypeId.isStringTypeId() && rightTypeId.isStringTypeId()) {
        DataTypeDescriptor rightTypeServices = rightOperand.getTypeServices();
        rightOperand = new CastNode(rightOperand, new DataTypeDescriptor(rightTypeId, true, rightTypeServices.getMaximumWidth()), getContextManager());
        ((CastNode) rightOperand).bindCastNodeOnly();
    } else if (!rightTypeId.isStringTypeId() && leftTypeId.isStringTypeId()) {
        DataTypeDescriptor leftTypeServices = leftOperand.getTypeServices();
        leftOperand = new CastNode(leftOperand, new DataTypeDescriptor(leftTypeId, true, leftTypeServices.getMaximumWidth()), getContextManager());
        ((CastNode) leftOperand).bindCastNodeOnly();
    }
    /* Test type compatability and set type info for this node */
    bindComparisonOperator();
    return this;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 45 with TypeId

use of org.apache.derby.iapi.types.TypeId in project derby by apache.

the class BinaryComparisonOperatorNode method genSQLJavaSQLTree.

/**
 * @see BinaryOperatorNode#genSQLJavaSQLTree
 */
@Override
ValueNode genSQLJavaSQLTree() throws StandardException {
    TypeId leftTypeId = leftOperand.getTypeId();
    /* If I have Java types, I need only add java->sql->java if the types
		 * are not comparable 
		 */
    if (leftTypeId.userType()) {
        if (leftOperand.getTypeServices().comparable(leftOperand.getTypeServices(), false, getClassFactory()))
            return this;
        leftOperand = leftOperand.genSQLJavaSQLTree();
    }
    TypeId rightTypeId = rightOperand.getTypeId();
    if (rightTypeId.userType()) {
        if (rightOperand.getTypeServices().comparable(rightOperand.getTypeServices(), false, getClassFactory()))
            return this;
        rightOperand = rightOperand.genSQLJavaSQLTree();
    }
    return this;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId)

Aggregations

TypeId (org.apache.derby.iapi.types.TypeId)53 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)32 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)8 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)6 ClassFactory (org.apache.derby.iapi.services.loader.ClassFactory)4 UserDefinedTypeIdImpl (org.apache.derby.catalog.types.UserDefinedTypeIdImpl)3 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)3 StandardException (org.apache.derby.shared.common.error.StandardException)3 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)2 DefaultInfoImpl (org.apache.derby.catalog.types.DefaultInfoImpl)2 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)2 ClassInspector (org.apache.derby.iapi.services.loader.ClassInspector)2 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 ProviderList (org.apache.derby.iapi.sql.depend.ProviderList)2 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)2 JSQLType (org.apache.derby.iapi.types.JSQLType)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1