public void processElement()

in dataflow/spanner-io/src/main/java/com/example/dataflow/EstimateSize.java [48:83]


    public void processElement(ProcessContext c) throws Exception {
      Struct row = c.element();
      long sum = 0;
      for (int i = 0; i < row.getColumnCount(); i++) {
        if (row.isNull(i)) {
          continue;
        }

        switch (row.getColumnType(i).getCode()) {
          case BOOL:
            sum += 1;
            break;
          case INT64:
          case FLOAT64:
            sum += 8;
            break;
          case TIMESTAMP:
          case DATE:
            sum += 12;
            break;
          case BYTES:
            sum += row.getBytes(i).length();
            break;
          case STRING:
            sum += row.getString(i).length();
            break;
          case ARRAY:
            throw new IllegalArgumentException("Arrays are not supported :(");
          case STRUCT:
            throw new IllegalArgumentException("Structs are not supported :(");
          default:
            throw new IllegalArgumentException("Unsupported type :(");
        }
      }
      c.output(sum);
    }