Search in sources :

Example 81 with DataTypeDescriptor

use of org.apache.derby.iapi.types.DataTypeDescriptor 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 82 with DataTypeDescriptor

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

the class AggregateNode method getNewAggregatorResultColumn.

/**
 * Get the result column that has a new aggregator.
 * This aggregator will be fed into the sorter.
 *
 * @param dd	the data dictionary
 *
 * @return the result column.  WARNING: it still needs to be bound
 *
 * @exception StandardException on error
 */
ResultColumn getNewAggregatorResultColumn(DataDictionary dd) throws StandardException {
    String className = aggregatorClassName.toString();
    DataTypeDescriptor compType = DataTypeDescriptor.getSQLDataTypeDescriptor(className);
    /*
		** Create a null of the right type.  The proper aggregators
		** are created dynamically by the SortObservers
		*/
    ConstantNode nullNode = getNullNode(compType);
    nullNode.bindExpression(// from
    null, // subquery
    null, // aggregate
    null);
    /*
		** Create a result column with this new node below
		** it.
		*/
    return new ResultColumn(aggregateName, nullNode, getContextManager());
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 83 with DataTypeDescriptor

use of org.apache.derby.iapi.types.DataTypeDescriptor 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 84 with DataTypeDescriptor

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

the class BinaryListOperatorNode method bindComparisonOperator.

/**
 * Test the type compatability of the operands and set the type info
 * for this node.  This method is useful both during binding and
 * when we generate nodes within the language module outside of the parser.
 *
 * @exception StandardException		Thrown on error
 */
void bindComparisonOperator() throws StandardException {
    boolean nullableResult;
    /* Can the types be compared to each other? */
    rightOperandList.comparable(leftOperand);
    /*
		** Set the result type of this comparison operator based on the
		** operands.  The result type is always SQLBoolean - the only question
		** is whether it is nullable or not.  If either the leftOperand or
		** any of the elements in the rightOperandList is
		** nullable, the result of the comparison must be nullable, too, so
		** we can represent the unknown truth value.
		*/
    nullableResult = leftOperand.getTypeServices().isNullable() || rightOperandList.isNullable();
    setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, nullableResult));
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 85 with DataTypeDescriptor

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

the class CreateIndexNode method makeConstantAction.

/**
 * Create the Constant information that will drive the guts of Execution.
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    SchemaDescriptor sd = getSchemaDescriptor();
    int columnCount = columnNames.length;
    int approxLength = 0;
    // so we do not have to consider key columns of long types
    for (int i = 0; i < columnCount; i++) {
        ColumnDescriptor columnDescriptor = td.getColumnDescriptor(columnNames[i]);
        DataTypeDescriptor dts = columnDescriptor.getType();
        approxLength += dts.getTypeId().getApproximateLengthInBytes(dts);
    }
    if (approxLength > Property.IDX_PAGE_SIZE_BUMP_THRESHOLD) {
        if (((properties == null) || (properties.get(Property.PAGE_SIZE_PARAMETER) == null)) && (PropertyUtil.getServiceProperty(getLanguageConnectionContext().getTransactionCompile(), Property.PAGE_SIZE_PARAMETER) == null)) {
            if (properties == null)
                properties = new Properties();
            properties.put(Property.PAGE_SIZE_PARAMETER, Property.PAGE_SIZE_DEFAULT_LONG);
        }
    }
    return getGenericConstantActionFactory().getCreateIndexConstantAction(// not for CREATE TABLE
    false, unique, // it's not a UniqueWithDuplicateNulls Index
    false, // it's not a constraint, so its checking
    false, // initiallyDeferred: N/A
    false, // constraintType: N/A
    -1, indexType, sd.getSchemaName(), indexName.getTableName(), tableName.getTableName(), td.getUUID(), columnNames, isAscending, false, null, properties);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) Properties(java.util.Properties)

Aggregations

DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)99 TypeId (org.apache.derby.iapi.types.TypeId)32 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)14 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)14 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)8 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)7 UUID (org.apache.derby.catalog.UUID)5 ClassFactory (org.apache.derby.iapi.services.loader.ClassFactory)5 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)5 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 Properties (java.util.Properties)4 UserDefinedTypeIdImpl (org.apache.derby.catalog.types.UserDefinedTypeIdImpl)4 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)4 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)3 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)3 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)3 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)3