public String cleanDataTypeValueSql()

in v2/datastream-to-sql/src/main/java/com/google/cloud/teleport/v2/utils/DatastreamToPostgresDML.java [83:121]


  public String cleanDataTypeValueSql(
      String columnValue, String columnName, Map<String, String> tableSchema) {
    String dataType = tableSchema.get(columnName);
    if (dataType == null) {
      return columnValue;
    }
    switch (dataType.toUpperCase()) {
      case "INT2":
      case "INT4":
      case "INT8":
      case "FLOAT4":
      case "FLOAT8":
      case "SMALLINT":
      case "INTEGER":
      case "BIGINT":
      case "DECIMAL":
      case "NUMERIC":
      case "REAL":
      case "DOUBLE PRECISION":
      case "SMALLSERIAL":
      case "SERIAL":
      case "BIGSERIAL":
        if (columnValue.equals("") || columnValue.equals("''")) {
          return getNullValueSql();
        }
        break;
      case "INTERVAL":
        return convertJsonToPostgresInterval(columnValue, columnName);
      case "BYTEA":
        // Byte arrays are converted to base64 string representation.
        return "decode(" + columnValue + ",'base64')";
    }

    // Arrays in Postgres are prefixed with underscore e.g. _INT4 for integer array.
    if (dataType.startsWith("_")) {
      return convertJsonToPostgresArray(columnValue, dataType.toUpperCase(), columnName);
    }
    return columnValue;
  }