private static void validateOptions()

in projects/dataflow-gcs-avro-to-spanner-scd/src/main/java/com/google/cloud/solutions/dataflow/avrotospannerscd/templates/AvroToSpannerScdPipeline.java [98:151]


  private static void validateOptions(AvroToSpannerScdOptions pipelineOptions) {
    checkArgument(
        pipelineOptions.getSpannerProjectId() == null
            || !isNullOrEmpty(pipelineOptions.getSpannerProjectId()),
        "When provided, Spanner project id must not be empty.");

    checkArgument(
        !pipelineOptions.getInstanceId().equals(""), "Spanner instance id must not be empty.");

    checkArgument(
        !pipelineOptions.getDatabaseId().equals(""), "Spanner database id must not be empty.");

    checkArgument(
        !isNullOrEmpty(pipelineOptions.getTableName()), "Spanner table name must not be empty.");

    checkArgument(
        pipelineOptions.getSpannerBatchSize() > 0,
        String.format(
            "Batch size must be greater than 0. Provided: %s.",
            pipelineOptions.getSpannerBatchSize()));

    checkArgument(
        !pipelineOptions.getPrimaryKeyColumnNames().isEmpty()
            && !pipelineOptions.getPrimaryKeyColumnNames().contains(""),
        "Spanner primary key column names must not be empty.");

    checkArgument(
        pipelineOptions.getOrderByColumnName() == null
            || !isNullOrEmpty(pipelineOptions.getOrderByColumnName()),
        "When provided, order by column name must not be empty.");

    switch (pipelineOptions.getScdType()) {
      case TYPE_1 -> {
        checkArgument(
            pipelineOptions.getStartDateColumnName() == null,
            "When using SCD Type 1, start date column name is not used.");
        checkArgument(
            pipelineOptions.getEndDateColumnName() == null,
            "When using SCD Type 1, end date column name is not used.");
      }
      case TYPE_2 -> {
        checkArgument(
            pipelineOptions.getStartDateColumnName() == null
                || !isNullOrEmpty(pipelineOptions.getStartDateColumnName()),
            "When provided, start date column name must not be empty.");
        checkNotNull(
            pipelineOptions.getEndDateColumnName(),
            "When using SCD Type 2, end date column name must be provided.");
        checkArgument(
            !isNullOrEmpty(pipelineOptions.getEndDateColumnName()),
            "When using SCD Type 2, end date column name must not be empty.");
      }
    }
  }