Java Code Examples for org.apache.phoenix.schema.PColumn#getScale()

The following examples show how to use org.apache.phoenix.schema.PColumn#getScale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexColumnNames.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private String getDataTypeString(PColumn col) {
    PDataType<?> dataType = col.getDataType();
    switch (dataType.getSqlType()) {
    case Types.DECIMAL:
        String typeStr = dataType.toString();
        if (col.getMaxLength() != null) {
            typeStr += "(" + col.getMaxLength().toString();
            if (col.getScale() != null) {
                typeStr += "," + col.getScale().toString();
            }
            typeStr += ")";
        }
        return typeStr;
    default:
        if (col.getMaxLength() != null) {
            return String.format("%s(%s)", dataType.toString(), col.getMaxLength());
        }
        return dataType.toString();
    }
}
 
Example 2
Source File: JoinCompiler.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void addProjectedColumn(List<PColumn> projectedColumns, List<Expression> sourceExpressions,
        ListMultimap<String, String> columnNameMap, PColumn sourceColumn, PName familyName, boolean hasSaltingColumn,
        boolean isLocalIndexColumnRef, StatementContext context)
throws SQLException {
    if (sourceColumn == SALTING_COLUMN)
        return;

    int position = projectedColumns.size() + (hasSaltingColumn ? 1 : 0);
    PTable table = tableRef.getTable();
    String schemaName = table.getSchemaName().getString();
    String tableName = table.getTableName().getString();
    String colName = isLocalIndexColumnRef ? IndexUtil.getIndexColumnName(sourceColumn) : sourceColumn.getName().getString();
    String fullName = getProjectedColumnName(schemaName, tableName, colName);
    String aliasedName = tableRef.getTableAlias() == null ? fullName : getProjectedColumnName(null, tableRef.getTableAlias(), colName);

    columnNameMap.put(colName, aliasedName);
    if (!fullName.equals(aliasedName)) {
        columnNameMap.put(fullName, aliasedName);
    }

    PName name = PNameFactory.newName(aliasedName);
    PColumnImpl column = new PColumnImpl(name, familyName, sourceColumn.getDataType(),
            sourceColumn.getMaxLength(), sourceColumn.getScale(), sourceColumn.isNullable(),
            position, sourceColumn.getSortOrder(), sourceColumn.getArraySize(), sourceColumn.getViewConstant(), sourceColumn.isViewReferenced(), sourceColumn.getExpressionStr());
    Expression sourceExpression = isLocalIndexColumnRef ?
              NODE_FACTORY.column(TableName.create(schemaName, tableName), "\"" + colName + "\"", null).accept(new ExpressionCompiler(context))
            : new ColumnRef(tableRef, sourceColumn.getPosition()).newColumnExpression();
    projectedColumns.add(column);
    sourceExpressions.add(sourceExpression);
}
 
Example 3
Source File: PhoenixRuntime.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param pCol
 * @return sql type name that could be used in DDL statements, dynamic column types etc. 
 */
public static String getSqlTypeName(PColumn pCol) {
    PDataType dataType = pCol.getDataType();
    Integer maxLength = pCol.getMaxLength();
    Integer scale = pCol.getScale();
    return dataType.isArrayType() ? getArraySqlTypeName(maxLength, scale, dataType) : appendMaxLengthAndScale(maxLength, scale, dataType.getSqlTypeName());
}
 
Example 4
Source File: IndexUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static PColumn getIndexPKColumn(int position, PColumn dataColumn) {
	assert (SchemaUtil.isPKColumn(dataColumn));
	PName indexColumnName = PNameFactory.newName(getIndexColumnName(null, dataColumn.getName().getString()));
	PColumn column = new PColumnImpl(indexColumnName, null, dataColumn.getDataType(), dataColumn.getMaxLength(),
			dataColumn.getScale(), dataColumn.isNullable(), position, dataColumn.getSortOrder(),
			dataColumn.getArraySize(), null, false, dataColumn.getExpressionStr(), dataColumn.isRowTimestamp(), false,
			// TODO set the columnQualifierBytes correctly
			/*columnQualifierBytes*/null, HConstants.LATEST_TIMESTAMP); 
	return column;
}
 
Example 5
Source File: PhoenixRuntime.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param pCol
 * @return sql type name that could be used in DDL statements, dynamic column types etc. 
 */
public static String getSqlTypeName(PColumn pCol) {
    PDataType dataType = pCol.getDataType();
    Integer maxLength = pCol.getMaxLength();
    Integer scale = pCol.getScale();
    return getSqlTypeName(dataType, maxLength, scale);
}