// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java
// public class BigQueryHelper {
//   private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class);
//   private static String keySource;
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @param key The google credentials JSON key that can be used to provide
//    *                    credentials to BigQuery, or null if no authentication should be performed.
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName, String key) {
//     if (key == null) {
//       return connect(projectName);
//     }
//     logger.debug("Attempting to open file {} for service account json key", key);
//     InputStream credentialsStream;
//     try {
//       if (keySource != null && keySource.equals("JSON")) {
//         credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8));
//       } else {
//         credentialsStream = new FileInputStream(key);
//       }
//       return new
//           BigQueryOptions.DefaultBigQueryFactory().create(
//               BigQueryOptions.newBuilder()
//                   .setProjectId(projectName)
//                   .setCredentials(GoogleCredentials.fromStream(credentialsStream))
//                   .build()
//       );
//     } catch (IOException err) {
//       throw new BigQueryConnectException("Failed to access json key file", err);
//     }
//   }
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param keySource The type of key config we can expect. This is either a String
//    *                        representation of the Google credentials file, or the path to the Google credentials file.
//    * @return The resulting BigQuery object.
//    */
//   public BigQueryHelper setKeySource(String keySource) {
//     this.keySource = keySource;
//     return this;
//   }
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with no authentication
//    * credentials, which can then be used for creating, updating, and inserting into tables from
//    * specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName) {
//     logger.debug("Attempting to access BigQuery without authentication");
//     return new BigQueryOptions.DefaultBigQueryFactory().create(
//             BigQueryOptions.newBuilder()
//                 .setProjectId(projectName)
//                 .build()
//     );
//   }
// }


import static com.google.cloud.bigquery.LegacySQLTypeName.BOOLEAN;
import static com.google.cloud.bigquery.LegacySQLTypeName.BYTES;
import static com.google.cloud.bigquery.LegacySQLTypeName.DATE;
import static com.google.cloud.bigquery.LegacySQLTypeName.FLOAT;
import static com.google.cloud.bigquery.LegacySQLTypeName.INTEGER;
import static com.google.cloud.bigquery.LegacySQLTypeName.STRING;
import static com.google.cloud.bigquery.LegacySQLTypeName.TIMESTAMP;
import static org.junit.Assert.assertEquals;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.FieldValue;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Schema;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableResult;
import com.wepay.kafka.connect.bigquery.BigQueryHelper;
import com.wepay.kafka.connect.bigquery.exception.SinkConfigConnectException;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;

      keyfile = properties.getProperty(KEYFILE_PROPERTY);
      if (keyfile == null) {
        throw new SinkConfigConnectException(
            "'" + KEYFILE_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      project = properties.getProperty(PROJECT_PROPERTY);
      if (project == null) {
        throw new SinkConfigConnectException(
            "'" + PROJECT_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      dataset = properties.getProperty(DATASET_PROPERTY);
      if (dataset == null) {
        throw new SinkConfigConnectException(
            "'" + DATASET_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      keySource = properties.getProperty(KEY_SOURCE_PROPERTY);
    }
  }

  private static void initializeBigQuery() throws Exception {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java
// public class BigQueryHelper {
//   private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class);
//   private static String keySource;
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @param key The google credentials JSON key that can be used to provide
//    *                    credentials to BigQuery, or null if no authentication should be performed.
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName, String key) {
//     if (key == null) {
//       return connect(projectName);
//     }
//     logger.debug("Attempting to open file {} for service account json key", key);
//     InputStream credentialsStream;
//     try {
//       if (keySource != null && keySource.equals("JSON")) {
//         credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8));
//       } else {
//         credentialsStream = new FileInputStream(key);
//       }
//       return new
//           BigQueryOptions.DefaultBigQueryFactory().create(
//               BigQueryOptions.newBuilder()
//                   .setProjectId(projectName)
//                   .setCredentials(GoogleCredentials.fromStream(credentialsStream))
//                   .build()
//       );
//     } catch (IOException err) {
//       throw new BigQueryConnectException("Failed to access json key file", err);
//     }
//   }
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param keySource The type of key config we can expect. This is either a String
//    *                        representation of the Google credentials file, or the path to the Google credentials file.
//    * @return The resulting BigQuery object.
//    */
//   public BigQueryHelper setKeySource(String keySource) {
//     this.keySource = keySource;
//     return this;
//   }
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with no authentication
//    * credentials, which can then be used for creating, updating, and inserting into tables from
//    * specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName) {
//     logger.debug("Attempting to access BigQuery without authentication");
//     return new BigQueryOptions.DefaultBigQueryFactory().create(
//             BigQueryOptions.newBuilder()
//                 .setProjectId(projectName)
//                 .build()
//     );
//   }
// }


// Path: kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/BigQueryConnectorIntegrationTest.java
import static com.google.cloud.bigquery.LegacySQLTypeName.BOOLEAN;
import static com.google.cloud.bigquery.LegacySQLTypeName.BYTES;
import static com.google.cloud.bigquery.LegacySQLTypeName.DATE;
import static com.google.cloud.bigquery.LegacySQLTypeName.FLOAT;
import static com.google.cloud.bigquery.LegacySQLTypeName.INTEGER;
import static com.google.cloud.bigquery.LegacySQLTypeName.STRING;
import static com.google.cloud.bigquery.LegacySQLTypeName.TIMESTAMP;
import static org.junit.Assert.assertEquals;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.FieldValue;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Schema;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableResult;
import com.wepay.kafka.connect.bigquery.BigQueryHelper;
import com.wepay.kafka.connect.bigquery.exception.SinkConfigConnectException;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;


      keyfile = properties.getProperty(KEYFILE_PROPERTY);
      if (keyfile == null) {
        throw new SinkConfigConnectException(
            "'" + KEYFILE_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      project = properties.getProperty(PROJECT_PROPERTY);
      if (project == null) {
        throw new SinkConfigConnectException(
            "'" + PROJECT_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      dataset = properties.getProperty(DATASET_PROPERTY);
      if (dataset == null) {
        throw new SinkConfigConnectException(
            "'" + DATASET_PROPERTY
            + "' property must be specified in test properties file"
        );
      }

      keySource = properties.getProperty(KEY_SOURCE_PROPERTY);
    }
  }

  private static void initializeBigQuery() throws Exception {
    bigQuery = new BigQueryHelper().setKeySource(keySource).connect(project, keyfile);