Java Code Examples for org.apache.beam.sdk.values.Row#getBaseValue()

The following examples show how to use org.apache.beam.sdk.values.Row#getBaseValue() . 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: SchemaAggregateFn.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public OutputT apply(Row row) {
  Row selected = rowSelector.select(row);
  if (fieldAggregation.needsFlattening) {
    selected = flatteningSelector.select(selected);
  }
  if (extractBaseValue
      && selected.getSchema().getField(0).getType().getTypeName().isLogicalType()) {
    return (OutputT) selected.getBaseValue(0, Object.class);
  }
  return selected.getValue(0);
}
 
Example 2
Source File: BeamSortRel.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(Row row1, Row row2) {
  for (int i = 0; i < fieldsIndices.size(); i++) {
    int fieldIndex = fieldsIndices.get(i);
    int fieldRet = 0;

    FieldType fieldType = row1.getSchema().getField(fieldIndex).getType();
    SqlTypeName sqlTypeName = CalciteUtils.toSqlTypeName(fieldType);
    // whether NULL should be ordered first or last(compared to non-null values) depends on
    // what user specified in SQL(NULLS FIRST/NULLS LAST)
    boolean isValue1Null = (row1.getValue(fieldIndex) == null);
    boolean isValue2Null = (row2.getValue(fieldIndex) == null);
    if (isValue1Null && isValue2Null) {
      continue;
    } else if (isValue1Null && !isValue2Null) {
      fieldRet = -1 * (nullsFirst.get(i) ? -1 : 1);
    } else if (!isValue1Null && isValue2Null) {
      fieldRet = 1 * (nullsFirst.get(i) ? -1 : 1);
    } else {
      switch (sqlTypeName) {
        case TINYINT:
        case SMALLINT:
        case INTEGER:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
        case VARCHAR:
        case DATE:
        case TIMESTAMP:
          Comparable v1 = row1.getBaseValue(fieldIndex, Comparable.class);
          Comparable v2 = row2.getBaseValue(fieldIndex, Comparable.class);
          fieldRet = v1.compareTo(v2);
          break;
        default:
          throw new UnsupportedOperationException(
              "Data type: " + sqlTypeName + " not supported yet!");
      }
    }

    fieldRet *= (orientation.get(i) ? 1 : -1);

    if (fieldRet != 0) {
      return fieldRet;
    }
  }
  return 0;
}