|
1 | 1 | package ai.chronon.integrations.cloud_gcp.test
|
2 | 2 |
|
| 3 | +import ai.chronon.integrations.cloud_gcp.GcpFormatProvider |
| 4 | +import ai.chronon.integrations.cloud_gcp.BQuery |
| 5 | +import ai.chronon.spark.{SparkSessionBuilder, TableUtils} |
3 | 6 | import org.scalatest.funsuite.AnyFunSuite
|
4 | 7 | import org.scalatestplus.mockito.MockitoSugar
|
5 | 8 |
|
6 |
| -class BigQueryCatalogTest extends AnyFunSuite with MockitoSugar {} |
| 9 | +class BigQueryCatalogTest extends AnyFunSuite with MockitoSugar { |
| 10 | + |
| 11 | + lazy val spark: SparkSession = SparkSessionBuilder.build( |
| 12 | + "BigQuerySparkTest", |
| 13 | + local = true, |
| 14 | + additionalConfig = Some( |
| 15 | + Map( |
| 16 | + "spark.chronon.table.format_provider.class" -> classOf[GcpFormatProvider].getName, |
| 17 | + "hive.metastore.uris" -> "thrift://localhost:9083", |
| 18 | + "spark.chronon.partition.column" -> "c", |
| 19 | + "spark.hadoop.fs.gs.impl" -> classOf[GoogleHadoopFileSystem].getName, |
| 20 | + "spark.hadoop.fs.AbstractFileSystem.gs.impl" -> classOf[GoogleHadoopFS].getName, |
| 21 | + "spark.hadoop.google.cloud.auth.service.account.enable" -> true.toString, |
| 22 | + "spark.hadoop.fs.gs.impl" -> classOf[GoogleHadoopFileSystem].getName |
| 23 | + )) |
| 24 | + ) |
| 25 | + lazy val tableUtils: TableUtils = TableUtils(spark) |
| 26 | + |
| 27 | + test("hive uris are set") { |
| 28 | + assertEquals("thrift://localhost:9083", spark.sqlContext.getConf("hive.metastore.uris")) |
| 29 | + } |
| 30 | + |
| 31 | + test("verify dynamic classloading of GCP providers") { |
| 32 | + |
| 33 | + assertTrue(tableUtils.tableReadFormat("data.sample_native") match { |
| 34 | + case BQuery(_) => true |
| 35 | + case _ => false |
| 36 | + }) |
| 37 | + } |
| 38 | + |
| 39 | + test("integration testing bigquery load table") { |
| 40 | + val externalTable = "data.checkouts_parquet" |
| 41 | + val table = tableUtils.loadTable(externalTable) |
| 42 | + val partitioned = tableUtils.isPartitioned(externalTable) |
| 43 | + val database = tableUtils.createDatabase("test_database") |
| 44 | + val allParts = tableUtils.allPartitions(externalTable) |
| 45 | + table.show |
| 46 | + } |
| 47 | + |
| 48 | + ignore("integration testing bigquery partitions") { |
| 49 | + // TODO(tchow): This test is ignored because it requires a running instance of the bigquery. Need to figure out stubbing locally. |
| 50 | + // to run this: |
| 51 | + // 1. Set up a tunnel to dataproc federation proxy: |
| 52 | + // gcloud compute ssh zipline-canary-cluster-m \ |
| 53 | + // --zone us-central1-c \ |
| 54 | + // -- -f -N -L 9083:localhost:9083 |
| 55 | + // 2. enable this test and off you go. |
| 56 | + val externalPartitions = tableUtils.partitions("data.checkouts_parquet") |
| 57 | + println(externalPartitions) |
| 58 | + val nativePartitions = tableUtils.partitions("data.sample_native") |
| 59 | + println(nativePartitions) |
| 60 | + } |
| 61 | +} |
0 commit comments