Java Code Examples for org.apache.kudu.Schema#getColumnCount()

The following examples show how to use org.apache.kudu.Schema#getColumnCount() . 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: KuduMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
    KuduTableHandle tableHandle = (KuduTableHandle) connectorTableHandle;
    Schema schema = clientSession.getTableSchema(tableHandle);

    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (int ordinal = 0; ordinal < schema.getColumnCount(); ordinal++) {
        ColumnSchema col = schema.getColumnByIndex(ordinal);
        String name = col.getName();
        Type type = TypeHelper.fromKuduColumn(col);
        KuduColumnHandle columnHandle = new KuduColumnHandle(name, ordinal, type);
        columnHandles.put(name, columnHandle);
    }

    return columnHandles.build();
}
 
Example 2
Source File: KuduToBigQuery.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
@Override
public TableRow apply(RowResult input) {
  TableRow outputTableRow = new TableRow();
  Schema kuduSchema = input.getSchema();

  for (int i = 0; i < kuduSchema.getColumnCount(); i++) {
    String columnName = kuduSchema.getColumnByIndex(i).getName();

    if (kuduSchema.getColumnByIndex(i).getType() == Type.UNIXTIME_MICROS) {
      outputTableRow.set(columnName, convertNanoSecondsToMilliSeconds(input, i));
    } else {
      // For other datatypes return the object value
      outputTableRow.set(columnName, input.getObject(i));
    }
  }
  return outputTableRow;
}
 
Example 3
Source File: KuduMetadata.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session,
                                                  ConnectorTableHandle connectorTableHandle) {
    KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle);
    Schema schema = clientSession.getTableSchema(tableHandle);

    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (int i = 0; i < schema.getColumnCount(); i++) {
        ColumnSchema col = schema.getColumnByIndex(i);
        String name = col.getName();
        Type type = TypeHelper.fromKuduColumn(col);
        KuduColumnHandle columnHandle = new KuduColumnHandle(name, i, type);
        columnHandles.put(name, columnHandle);
    }

    return columnHandles.build();
}
 
Example 4
Source File: KuduReaderIterator.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
private Row toFlinkRow(RowResult row) {
    Schema schema = row.getColumnProjection();

    Row values = new Row(schema.getColumnCount());
    schema.getColumns().forEach(column -> {
        String name = column.getName();
        int pos = schema.getColumnIndex(name);
        values.setField(pos, row.getObject(name));
    });
    return values;
}
 
Example 5
Source File: KuduMapper.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
static KuduRow toKuduRow(RowResult row) {
    Schema schema = row.getColumnProjection();

    KuduRow values = new KuduRow(schema.getColumnCount());
    schema.getColumns().forEach(column -> {
        String name = column.getName();
        int pos = schema.getColumnIndex(name);
        if(row.isNull(name)) {
            values.setField(pos, name, null);
        } else {
            Type type = column.getType();
            switch (type) {
                case BINARY:
                    values.setField(pos, name, row.getBinary(name));
                    break;
                case STRING:
                    values.setField(pos, name, row.getString(name));
                    break;
                case BOOL:
                    values.setField(pos, name, row.getBoolean(name));
                    break;
                case DOUBLE:
                    values.setField(pos, name, row.getDouble(name));
                    break;
                case FLOAT:
                    values.setField(pos, name, row.getFloat(name));
                    break;
                case INT8:
                    values.setField(pos, name, row.getByte(name));
                    break;
                case INT16:
                    values.setField(pos, name, row.getShort(name));
                    break;
                case INT32:
                    values.setField(pos, name, row.getInt(name));
                    break;
                case INT64:
                    values.setField(pos, name, row.getLong(name));
                    break;
                case UNIXTIME_MICROS:
                    values.setField(pos, name, row.getLong(name) / 1000);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return values;
}
 
Example 6
Source File: KuduMapper.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
static KuduRow toKuduRow(RowResult row) {
    Schema schema = row.getColumnProjection();

    KuduRow values = new KuduRow(schema.getColumnCount());
    schema.getColumns().forEach(column -> {
        String name = column.getName();
        int pos = schema.getColumnIndex(name);
        if(row.isNull(name)) {
            values.setField(pos, name, null);
        } else {
            Type type = column.getType();
            switch (type) {
                case BINARY:
                    values.setField(pos, name, row.getBinary(name));
                    break;
                case STRING:
                    values.setField(pos, name, row.getString(name));
                    break;
                case BOOL:
                    values.setField(pos, name, row.getBoolean(name));
                    break;
                case DOUBLE:
                    values.setField(pos, name, row.getDouble(name));
                    break;
                case FLOAT:
                    values.setField(pos, name, row.getFloat(name));
                    break;
                case INT8:
                    values.setField(pos, name, row.getByte(name));
                    break;
                case INT16:
                    values.setField(pos, name, row.getShort(name));
                    break;
                case INT32:
                    values.setField(pos, name, row.getInt(name));
                    break;
                case INT64:
                    values.setField(pos, name, row.getLong(name));
                    break;
                case UNIXTIME_MICROS:
                    values.setField(pos, name, row.getLong(name) / 1000);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return values;
}