// Path: services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/entities/NonRetryableApplicationException.java
// public class NonRetryableApplicationException extends Exception {
//     public NonRetryableApplicationException(String msg){
//         super(msg);
//     }
// }


import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.TableResult;
import com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException;
import java.util.ArrayList;
import java.util.List;
        return projectDatasets;
    }

    @Override
    // List all tables in a dataset/project that have DLP findings
    public List<String> listTables(String project, String dataset) throws InterruptedException, NonRetryableApplicationException {
        // Get all tables under this dataset that was scanned by DLP
        String formattedQuery = String.format(
                "SELECT DISTINCT table_spec AS table FROM `%s` WHERE CONCAT(project_id, '.', dataset_id) = '%s.%s'",
                dlpFindingsView,
                project,
                dataset
        );

        // Create a job ID so that we can safely retry.
        Job queryJob = bqService.submitJob(formattedQuery);

        TableResult result = bqService.waitAndGetJobResults(queryJob);

        // Construct a mapping between field names and DLP infotypes
        List<String> datasetTables = new ArrayList<>();
        for (FieldValueList row : result.iterateAll()) {

            if (row.get("table").isNull()) {
                throw new NonRetryableApplicationException("processDatasets query returned rows with null 'table' field.");
            }
            String tableSpec = row.get("table").getStringValue();
            datasetTables.add(tableSpec);
        }

// Path: services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/entities/NonRetryableApplicationException.java
// public class NonRetryableApplicationException extends Exception {
//     public NonRetryableApplicationException(String msg){
//         super(msg);
//     }
// }


// Path: services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/services/DlpResultsScannerImpl.java
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.TableResult;
import com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException;
import java.util.ArrayList;
import java.util.List;

        return projectDatasets;
    }

    @Override
    // List all tables in a dataset/project that have DLP findings
    public List<String> listTables(String project, String dataset) throws InterruptedException, NonRetryableApplicationException {
        // Get all tables under this dataset that was scanned by DLP
        String formattedQuery = String.format(
                "SELECT DISTINCT table_spec AS table FROM `%s` WHERE CONCAT(project_id, '.', dataset_id) = '%s.%s'",
                dlpFindingsView,
                project,
                dataset
        );

        // Create a job ID so that we can safely retry.
        Job queryJob = bqService.submitJob(formattedQuery);

        TableResult result = bqService.waitAndGetJobResults(queryJob);

        // Construct a mapping between field names and DLP infotypes
        List<String> datasetTables = new ArrayList<>();
        for (FieldValueList row : result.iterateAll()) {

            if (row.get("table").isNull()) {
                throw new NonRetryableApplicationException("processDatasets query returned rows with null 'table' field.");
            }
            String tableSpec = row.get("table").getStringValue();
            datasetTables.add(tableSpec);
        }

        return datasetTables;