Search in sources :

Example 86 with DataTypeDescriptor

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

the class VTIResultSet method populateFromResultSet.

/**
 * @exception StandardException thrown on failure to open
 */
public void populateFromResultSet(ExecRow row) throws StandardException {
    try {
        DataTypeDescriptor[] columnTypes = null;
        if (isDerbyStyleTableFunction) {
            columnTypes = getReturnColumnTypes();
        }
        boolean[] nullableColumn = setNullableColumnList();
        DataValueDescriptor[] columns = row.getRowArray();
        // ExecRows are 0-based, ResultSets are 1-based
        int rsColNumber = 1;
        for (int index = 0; index < columns.length; index++) {
            // Skip over unreferenced columns
            if (referencedColumns != null && (!referencedColumns.get(index))) {
                if (!pushedProjection)
                    rsColNumber++;
                continue;
            }
            columns[index].setValueFromResultSet(userVTI, rsColNumber, /* last parameter is whether or
									 * not the column is nullable
									 */
            nullableColumn[rsColNumber]);
            rsColNumber++;
            // column
            if (isDerbyStyleTableFunction) {
                DataTypeDescriptor dtd = columnTypes[index];
                DataValueDescriptor dvd = columns[index];
                cast(dtd, dvd);
            }
        }
    } catch (StandardException se) {
        throw se;
    } catch (Throwable t) {
        throw StandardException.unexpectedUserException(t);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 87 with DataTypeDescriptor

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

the class NormalizeResultSet method fetchResultTypes.

/**
 * <p>
 * Fetch the result datatypes out of the activation.
 * </p>
 */
private DataTypeDescriptor[] fetchResultTypes(ResultDescription desc) {
    int count = desc.getColumnCount();
    DataTypeDescriptor[] result = new DataTypeDescriptor[count];
    for (int i = 1; i <= count; i++) {
        ResultColumnDescriptor colDesc = desc.getColumnDescriptor(i);
        DataTypeDescriptor dtd = colDesc.getType();
        result[i - 1] = dtd;
    }
    return result;
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 88 with DataTypeDescriptor

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

the class DMLModStatementNode method parseAndBindGenerationClauses.

/**
 * Parse and bind the generating expressions of computed columns.
 *
 * @param dataDictionary    metadata
 * @param targetTableDescriptor metadata for the table that has the generated columns
 * @param sourceRCL  the tuple stream which drives the INSERT or UPDATE
 * @param targetRCL  the row in the table that's being INSERTed or UPDATEd
 * @param forUpdate true if this is an UPDATE. false otherwise.
 * @param updateResultSet more information on the tuple stream driving the UPDATE
 */
void parseAndBindGenerationClauses(DataDictionary dataDictionary, TableDescriptor targetTableDescriptor, ResultColumnList sourceRCL, ResultColumnList targetRCL, boolean forUpdate, ResultSetNode updateResultSet) throws StandardException {
    CompilerContext compilerContext = getCompilerContext();
    int count = targetRCL.size();
    for (int i = 0; i < count; i++) {
        ResultColumn rc = targetRCL.elementAt(i);
        // 
        if (forUpdate && !rc.updated()) {
            continue;
        }
        if (rc.hasGenerationClause()) {
            ColumnDescriptor colDesc = rc.getTableColumnDescriptor();
            DataTypeDescriptor dtd = colDesc.getType();
            DefaultInfo di = colDesc.getDefaultInfo();
            ValueNode generationClause = parseGenerationClause(di.getDefaultText(), targetTableDescriptor);
            // insert CAST in case column data type is not same as the
            // resolved type of the generation clause
            generationClause = new CastNode(generationClause, dtd, getContextManager());
            // Assignment semantics of implicit cast here:
            // Section 9.2 (Store assignment). There, General Rule
            // 2.b.v.2 says that the database should raise an exception
            // if truncation occurs when stuffing a string value into a
            // VARCHAR, so make sure CAST doesn't issue warning only.
            ((CastNode) generationClause).setAssignmentSemantics();
            // 
            // Unqualified function references should resolve to the
            // current schema at the time that the table was
            // created/altered. See DERBY-3945.
            // 
            compilerContext.pushCompilationSchema(getSchemaDescriptor(di.getOriginalCurrentSchema(), false));
            try {
                bindRowScopedExpression(getOptimizerFactory(), getContextManager(), targetTableDescriptor, sourceRCL, generationClause);
            } finally {
                compilerContext.popCompilationSchema();
            }
            ResultColumn newRC = new ResultColumn(generationClause.getTypeServices(), generationClause, getContextManager());
            // replace the result column in place
            // column ids are 1-based
            newRC.setVirtualColumnId(i + 1);
            newRC.setColumnDescriptor(targetTableDescriptor, colDesc);
            targetRCL.setElementAt(newRC, i);
            // generate correctly if they reference the generated column
            if (forUpdate) {
                for (int j = 0; j < sourceRCL.size(); j++) {
                    if (rc == sourceRCL.elementAt(j)) {
                        newRC.setName(rc.getName());
                        newRC.setResultSetNumber(updateResultSet.getResultSetNumber());
                        sourceRCL.setElementAt(newRC, j);
                    }
                }
            // end of loop through sourceRCL
            }
        // end if this is an update statement
        }
    // end if this is a generated column
    }
// end of loop through targetRCL
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DefaultInfo(org.apache.derby.catalog.DefaultInfo) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 89 with DataTypeDescriptor

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

the class FromVTI method createResultColumnsForTableFunction.

/**
 * Add result columns for a Derby-style Table Function
 */
private void createResultColumnsForTableFunction(TypeDescriptor td) throws StandardException {
    String[] columnNames = td.getRowColumnNames();
    TypeDescriptor[] types = td.getRowTypes();
    for (int i = 0; i < columnNames.length; i++) {
        String columnName = columnNames[i];
        DataTypeDescriptor dtd = DataTypeDescriptor.getType(types[i]);
        ResultColumn rc = getResultColumns().addColumn(exposedName, columnName, dtd);
        // 
        // Stuff a column descriptor into the ResultColumn. We do this so that
        // getColumnPosition() will return the column position within the
        // table function's shape. Later on, projection may remove columns
        // from the ResultColumnList. We don't want getColumnPosition() to say
        // that the column position is the index into the abbreviated ResultColumnList.
        // See DERBY-6040.
        // 
        ColumnDescriptor coldesc = new ColumnDescriptor(columnName, i + 1, dtd, (DataValueDescriptor) null, (DefaultInfo) null, (UUID) null, (UUID) null, 0L, 0L, 0L, false);
        rc.setColumnDescriptor(null, coldesc);
    }
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 90 with DataTypeDescriptor

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

the class LengthOperatorNode 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 {
    TypeId operandType;
    bindOperand(fromList, subqueryList, aggregates);
    /*
		** Check the type of the operand - this function is allowed only on
		** string value types.  
		*/
    operandType = operand.getTypeId();
    switch(operandType.getJDBCTypeId()) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.LONGVARCHAR:
        case Types.BLOB:
        case Types.CLOB:
            break;
        default:
            throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, getOperatorString(), operandType.getSQLTypeName());
    }
    /*
		** The result type of XXX_length is int.
		*/
    setType(new DataTypeDescriptor(TypeId.INTEGER_ID, operand.getTypeServices().isNullable()));
    return this;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

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