class ZetaSqlUtils {

  public static Object zetaSqlValueToJavaObject(Value value, FieldType fieldType) {
    if (value.isNull()) {
      return null;
    }
    switch (fieldType.getTypeName()) {
      case INT64:
        return value.getInt64Value();
      case DECIMAL:
        return value.getNumericValue();
      case DOUBLE:
        // Floats with a floating part equal to zero are treated as whole (INT64).
        // Cast to double when that happens.
        if (value.getType().getKind().equals(TypeKind.TYPE_INT64)) {
          return (double) value.getInt64Value();
        }
        return value.getDoubleValue();
      case STRING:
        return value.getStringValue();
      case DATETIME:
        return zetaSqlTimestampValueToJodaInstant(value);
      case BOOLEAN:
        return value.getBoolValue();
      case BYTES:
        return value.getBytesValue().toByteArray();
      case ARRAY:
        return zetaSqlArrayValueToJavaList(value, fieldType.getCollectionElementType());
      case ROW:
        return zetaSqlStructValueToBeamRow(value, fieldType.getRowSchema());
      default:
        throw new UnsupportedOperationException(
            "Unsupported Beam fieldType: " + fieldType.getTypeName());
    }
  }

  private  ZetaSqlUtils();

}