Search in sources :

Example 1 with ResultColumnMetadata

use of org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata in project drill by apache.

the class PreparedStatementProvider method serializeColumn.

/**
   * Serialize the given {@link SerializedField} into a {@link ResultColumnMetadata}.
   * @param field
   * @return
   */
private static ResultColumnMetadata serializeColumn(SerializedField field) {
    final ResultColumnMetadata.Builder builder = ResultColumnMetadata.newBuilder();
    final MajorType majorType = field.getMajorType();
    final MinorType minorType = majorType.getMinorType();
    /**
     * Defaults to "DRILL" as drill has as only one catalog.
     */
    builder.setCatalogName(InfoSchemaConstants.IS_CATALOG_NAME);
    /**
     * Designated column's schema name. Empty string if not applicable. Initial implementation defaults to empty string
     * as we use LIMIT 0 queries to get the schema and schema info is lost. If we derive the schema from plan, we may
     * get the right value.
     */
    builder.setSchemaName("");
    /**
     * Designated column's table name. Not set if not applicable. Initial implementation defaults to empty string as
     * we use LIMIT 0 queries to get the schema and table info is lost. If we derive the table from plan, we may get
     * the right value.
     */
    builder.setTableName("");
    builder.setColumnName(field.getNamePart().getName());
    /**
     * Column label name for display or print purposes.
     * Ex. a column named "empName" might be labeled as "Employee Name".
     * Initial implementation defaults to same value as column name.
     */
    builder.setLabel(field.getNamePart().getName());
    /**
     * Data type in string format. Value is SQL standard type.
     */
    builder.setDataType(Types.getSqlTypeName(majorType));
    builder.setIsNullable(majorType.getMode() == DataMode.OPTIONAL);
    /**
     * For numeric data, this is the maximum precision.
     * For character data, this is the length in characters.
     * For datetime data types, this is the length in characters of the String representation
     *    (assuming the maximum allowed precision of the fractional seconds component).
     * For binary data, this is the length in bytes.
     * For all other types 0 is returned where the column size is not applicable.
     */
    builder.setPrecision(Types.getPrecision(field.getMajorType()));
    /**
     * Column's number of digits to right of the decimal point. 0 is returned for types where the scale is not applicable
     */
    builder.setScale(Types.getScale(majorType));
    /**
     * Indicates whether values in the designated column are signed numbers.
     */
    builder.setSigned(Types.isNumericType(majorType));
    /**
     * Maximum number of characters required to display data from the column.
     */
    builder.setDisplaySize(Types.getJdbcDisplaySize(majorType));
    /**
     * Is the column an aliased column. Initial implementation defaults to true as we derive schema from LIMIT 0 query and
     * not plan
     */
    builder.setIsAliased(true);
    builder.setSearchability(ColumnSearchability.ALL);
    builder.setUpdatability(ColumnUpdatability.READ_ONLY);
    builder.setAutoIncrement(false);
    builder.setCaseSensitivity(false);
    builder.setSortable(Types.isSortable(minorType));
    /**
     * Returns the fully-qualified name of the Java class whose instances are manufactured if the method
     * ResultSet.getObject is called to retrieve a value from the column. Applicable only to JDBC clients.
     */
    builder.setClassName(DRILL_TYPE_TO_JDBC_CLASSNAME.get(minorType));
    builder.setIsCurrency(false);
    return builder.build();
}
Also used : ResultColumnMetadata(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 2 with ResultColumnMetadata

use of org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata in project drill by apache.

the class DrillColumnMetaDataList method updateColumnMetaData.

/**
   * Update the metadata with given metadata received from server.
   * @param metadata
   */
public void updateColumnMetaData(List<ResultColumnMetadata> metadata) {
    final List<ColumnMetaData> newColumns = new ArrayList<>(metadata.size());
    int offset = 0;
    for (ResultColumnMetadata m : metadata) {
        final AvaticaType bundledSqlDataType = getAvaticaType(m.getDataType());
        newColumns.add(new ColumnMetaData(offset, m.getAutoIncrement(), m.getCaseSensitivity(), m.getSearchability() != ColumnSearchability.NONE, m.getIsCurrency(), m.getIsNullable() ? ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls, m.getSigned(), m.getDisplaySize(), m.getLabel(), m.getColumnName(), m.getSchemaName(), m.getPrecision(), m.getScale(), m.getTableName(), m.getCatalogName(), bundledSqlDataType, m.getUpdatability() == ColumnUpdatability.READ_ONLY, m.getUpdatability() == ColumnUpdatability.WRITABLE, m.getUpdatability() == ColumnUpdatability.WRITABLE, m.getClassName()));
        offset++;
    }
    columns = ImmutableList.copyOf(newColumns);
}
Also used : ResultColumnMetadata(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata) AvaticaType(org.apache.calcite.avatica.ColumnMetaData.AvaticaType) ArrayList(java.util.ArrayList) ColumnMetaData(org.apache.calcite.avatica.ColumnMetaData)

Aggregations

ResultColumnMetadata (org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata)2 ArrayList (java.util.ArrayList)1 ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)1 AvaticaType (org.apache.calcite.avatica.ColumnMetaData.AvaticaType)1 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1