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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations