|
31 | 31 |
|
32 | 32 | import com.google.api.gax.paging.Page; |
33 | 33 | import com.google.cloud.bigquery.*; |
34 | | -import com.google.cloud.bigquery.BigQuery.RoutineListOption; |
35 | 34 | import com.google.cloud.bigquery.exception.BigQueryJdbcException; |
36 | 35 | import com.google.cloud.bigquery.jdbc.BigQueryJdbcTypeMappings.ColumnTypeInfo; |
37 | 36 | import io.opentelemetry.api.common.AttributeKey; |
|
49 | 48 | import java.sql.Statement; |
50 | 49 | import java.sql.Types; |
51 | 50 | import java.util.*; |
52 | | -import java.util.concurrent.Callable; |
53 | | -import java.util.concurrent.ExecutionException; |
54 | 51 | import java.util.concurrent.ExecutorService; |
55 | 52 | import java.util.concurrent.Executors; |
56 | | -import java.util.concurrent.Future; |
57 | 53 | import java.util.regex.Pattern; |
58 | 54 | import java.util.stream.Stream; |
59 | 55 | import org.junit.jupiter.api.AfterEach; |
@@ -761,7 +757,7 @@ public void testProcessSchemaInfo() { |
761 | 757 | String schemaName = "dataset_beta"; |
762 | 758 | Dataset dataset = mockBigQueryDataset(catalog, schemaName); |
763 | 759 |
|
764 | | - dbMetadata.processSchemaInfo(dataset, collectedResults, resultSchemaFields); |
| 760 | + dbMetadata.processSchemaInfo(dataset.getDatasetId(), collectedResults, resultSchemaFields); |
765 | 761 |
|
766 | 762 | assertEquals(1, collectedResults.size()); |
767 | 763 | FieldValueList row = collectedResults.get(0); |
@@ -1614,96 +1610,6 @@ public void testDefineGetProcedureColumnsComparator() { |
1614 | 1610 | assertEquals("param_a", results.get(4).get("COLUMN_NAME").getStringValue()); |
1615 | 1611 | } |
1616 | 1612 |
|
1617 | | - @Test |
1618 | | - public void testListMatchingProcedureIdsFromDatasets() throws Exception { |
1619 | | - String catalog = "test-proj"; |
1620 | | - String schema1Name = "dataset1"; |
1621 | | - String schema2Name = "dataset2"; |
1622 | | - Dataset dataset1 = mockBigQueryDataset(catalog, schema1Name); |
1623 | | - Dataset dataset2 = mockBigQueryDataset(catalog, schema2Name); |
1624 | | - List<Dataset> datasetsToScan = Arrays.asList(dataset1, dataset2); |
1625 | | - |
1626 | | - Routine proc1_ds1 = mockBigQueryRoutine(catalog, schema1Name, "proc_a", "PROCEDURE", "desc a"); |
1627 | | - Routine func1_ds1 = mockBigQueryRoutine(catalog, schema1Name, "func_b", "FUNCTION", "desc b"); |
1628 | | - Routine proc2_ds2 = mockBigQueryRoutine(catalog, schema2Name, "proc_c", "PROCEDURE", "desc c"); |
1629 | | - |
1630 | | - Page<Routine> page1 = mock(Page.class, withSettings().withoutAnnotations()); |
1631 | | - when(page1.iterateAll()).thenReturn(Arrays.asList(proc1_ds1, func1_ds1)); |
1632 | | - when(bigqueryClient.listRoutines(eq(dataset1.getDatasetId()), any(RoutineListOption.class))) |
1633 | | - .thenReturn(page1); |
1634 | | - |
1635 | | - Page<Routine> page2 = mock(Page.class, withSettings().withoutAnnotations()); |
1636 | | - when(page2.iterateAll()).thenReturn(Collections.singletonList(proc2_ds2)); |
1637 | | - when(bigqueryClient.listRoutines(eq(dataset2.getDatasetId()), any(RoutineListOption.class))) |
1638 | | - .thenReturn(page2); |
1639 | | - |
1640 | | - ExecutorService mockExecutor = mock(ExecutorService.class); |
1641 | | - doAnswer( |
1642 | | - invocation -> { |
1643 | | - Callable<?> callable = invocation.getArgument(0); |
1644 | | - @SuppressWarnings("unchecked") // Suppress warning for raw Future mock |
1645 | | - Future<Object> mockedFuture = mock(Future.class); |
1646 | | - |
1647 | | - try { |
1648 | | - Object result = callable.call(); |
1649 | | - doReturn(result).when(mockedFuture).get(); |
1650 | | - } catch (InterruptedException interruptedException) { |
1651 | | - doThrow(interruptedException).when(mockedFuture).get(); |
1652 | | - } catch (Exception e) { |
1653 | | - doThrow(new ExecutionException(e)).when(mockedFuture).get(); |
1654 | | - } |
1655 | | - return mockedFuture; |
1656 | | - }) |
1657 | | - .when(mockExecutor) |
1658 | | - .submit(any(Callable.class)); |
1659 | | - |
1660 | | - List<RoutineId> resultIds = |
1661 | | - dbMetadata.listMatchingProcedureIdsFromDatasets( |
1662 | | - datasetsToScan, null, null, mockExecutor, catalog, dbMetadata.LOG); |
1663 | | - |
1664 | | - assertEquals(2, resultIds.size()); |
1665 | | - assertTrue(resultIds.contains(proc1_ds1.getRoutineId())); |
1666 | | - assertTrue(resultIds.contains(proc2_ds2.getRoutineId())); |
1667 | | - assertFalse(resultIds.contains(func1_ds1.getRoutineId())); // Should not contain functions |
1668 | | - |
1669 | | - verify(mockExecutor, times(2)).submit(any(Callable.class)); |
1670 | | - } |
1671 | | - |
1672 | | - @Test |
1673 | | - public void testProcessProcedureArgumentsSequentially_Basic() throws InterruptedException { |
1674 | | - String catalog = "p"; |
1675 | | - String schemaName = "d"; |
1676 | | - RoutineArgument arg1 = mockRoutineArgument("arg1_name", StandardSQLTypeName.STRING, "IN"); |
1677 | | - Routine proc1 = |
1678 | | - mockBigQueryRoutineWithArgs( |
1679 | | - catalog, schemaName, "proc1", "PROCEDURE", "desc1", Collections.singletonList(arg1)); |
1680 | | - Routine func1 = |
1681 | | - mockBigQueryRoutineWithArgs( |
1682 | | - catalog, |
1683 | | - schemaName, |
1684 | | - "func1", |
1685 | | - "FUNCTION", |
1686 | | - "desc_func", |
1687 | | - Collections.emptyList()); // Should be skipped |
1688 | | - Routine proc2 = |
1689 | | - mockBigQueryRoutineWithArgs( |
1690 | | - catalog, schemaName, "proc2", "PROCEDURE", "desc2", Collections.emptyList()); |
1691 | | - |
1692 | | - List<Routine> fullRoutines = Arrays.asList(proc1, func1, proc2); |
1693 | | - Pattern columnNameRegex = null; |
1694 | | - List<FieldValueList> collectedResults = Collections.synchronizedList(new ArrayList<>()); |
1695 | | - Schema resultSchema = dbMetadata.defineGetProcedureColumnsSchema(); |
1696 | | - FieldList resultSchemaFields = resultSchema.getFields(); |
1697 | | - |
1698 | | - dbMetadata.processProcedureArgumentsSequentially( |
1699 | | - fullRoutines, columnNameRegex, collectedResults, resultSchemaFields, dbMetadata.LOG); |
1700 | | - |
1701 | | - // Only proc1 has arguments, so collectedResults should contain 1 row. |
1702 | | - assertEquals(1, collectedResults.size()); |
1703 | | - FieldValueList row = collectedResults.get(0); |
1704 | | - assertEquals("arg1_name", row.get("COLUMN_NAME").getStringValue()); |
1705 | | - } |
1706 | | - |
1707 | 1613 | @Test |
1708 | 1614 | public void testDefineGetTableTypesSchema() { |
1709 | 1615 | Schema schema = BigQueryDatabaseMetaData.defineGetTableTypesSchema(); |
|
0 commit comments