static <E> List<List<E>> create(List<? extends List<? extends E>> lists) { ImmutableList.Builder<List<E>> axesBuilder = new ImmutableList.Builder<>(lists.size()); for (List<? extends E> list : lists) { List<E> copy = ImmutableList.copyOf(list); if (copy.isEmpty()) { return ImmutableList.of(); } axesBuilder.add(copy); } return new CartesianList<E>(axesBuilder.build()); }
@Test public void testGroupingOperationSomeBitsSet() { List<Integer> groupingOrdinals = ImmutableList.of(7, 2, 9, 3, 5); List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(4, 2), ImmutableSet.of(9, 7, 14), ImmutableSet.of(5, 2, 7), ImmutableSet.of(3)); List<Long> expectedResults = ImmutableList.of(23L, 11L, 6L, 29L); for (int groupId = 0; groupId < groupingSetOrdinals.size(); groupId++) { Set<Integer> groupingSet = groupingSetOrdinals.get(groupId); assertEquals(Long.valueOf(calculateGrouping(groupingSet, groupingOrdinals)), expectedResults.get(groupId)); } }
@Test public void testAddresses() { // split uses "example" scheme so no addresses are available and is not remotely accessible assertEquals(split.getAddresses(), ImmutableList.of()); assertEquals(split.isRemotelyAccessible(), true); JdbcSplit jdbcSplit = new JdbcSplit("connectorId", "catalog", "schemaName", "tableName", TupleDomain.all(), Optional.empty()); assertEquals(jdbcSplit.getAddresses(), ImmutableList.of()); }
@Test public void tableIsCreatedAfterCommits() { assertNoTables(); SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table"); ConnectorOutputTableHandle table = metadata.beginCreateTable( SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty()); metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of()); List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty()); assertTrue(tables.size() == 1, "Expected only one table"); assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'"); }
@Test public void testRequiredColumns() { Assert.assertEquals(ImmutableList.of("x", "y"), X_PLUS_Y.requiredColumns()); Assert.assertEquals(ImmutableList.of(), CONSTANT_LIKE.requiredColumns()); Assert.assertEquals(ImmutableList.of("z"), Z_LIKE.requiredColumns()); Assert.assertEquals(ImmutableList.of("z", "x"), Z_CONCAT_X.requiredColumns()); }
@Test public void testTableSampleBernoulli() { DescriptiveStatistics stats = new DescriptiveStatistics(); int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows().size(); for (int i = 0; i < 100; i++) { List<MaterializedRow> values = computeActual("SELECT orderkey FROM orders TABLESAMPLE BERNOULLI (50)").getMaterializedRows(); assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows"); stats.addValue(values.size() * 1.0 / total); } double mean = stats.getGeometricMean(); assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean)); }
@Test public void testDateColumn() { IonSqlQueryBuilder queryBuilder = new IonSqlQueryBuilder(new TypeRegistry()); List<HiveColumnHandle> columns = ImmutableList.of( new HiveColumnHandle("t1", HIVE_TIMESTAMP, parseTypeSignature(TIMESTAMP), 0, REGULAR, Optional.empty()), new HiveColumnHandle("t2", HIVE_DATE, parseTypeSignature(StandardTypes.DATE), 1, REGULAR, Optional.empty())); TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of( columns.get(1), Domain.create(SortedRangeSet.copyOf(DATE, ImmutableList.of(Range.equal(DATE, (long) DateTimeUtils.parseDate("2001-08-22")))), false))); assertEquals("SELECT s._1, s._2 FROM S3Object s WHERE (case s._2 when '' then null else CAST(s._2 AS TIMESTAMP) end = `2001-08-22`)", queryBuilder.buildSql(columns, tupleDomain)); }
@Test public void testSelectCount() throws Exception { final ResultSet resultSet = client.createStatement().executeQuery("SELECT COUNT(*) AS cnt FROM druid.foo"); final List<Map<String, Object>> rows = getRows(resultSet); Assert.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6L) ), rows ); }
@Test public void testArrayHistograms() { ArrayType arrayType = new ArrayType(VARCHAR); MapType mapType = mapType(arrayType, BIGINT); InternalAggregationFunction aggregationFunction = getAggregation(mapType.getTypeSignature(), arrayType.getTypeSignature()); assertAggregation( aggregationFunction, ImmutableMap.of(ImmutableList.of("a", "b", "c"), 1L, ImmutableList.of("d", "e", "f"), 1L, ImmutableList.of("c", "b", "a"), 1L), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b", "c"), ImmutableList.of("d", "e", "f"), ImmutableList.of("c", "b", "a")))); }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*" + INVALID_COLUMN + ".*") public void testGetRecordsInvalidColumn() throws Exception { try (Transaction transaction = newTransaction()) { ConnectorMetadata connectorMetadata = transaction.getMetadata(); ConnectorTableHandle table = getTableHandle(connectorMetadata, tableUnpartitioned); readTable(transaction, table, ImmutableList.of(invalidColumnHandle), newSession(), TupleDomain.all(), OptionalInt.empty(), Optional.empty()); } }
@Test public void testAdjacentNode_nodeNotIncident() { ImmutableList<MutableNetwork<Integer, String>> testNetworks = ImmutableList.of( NetworkBuilder.directed().<Integer, String>build(), NetworkBuilder.undirected().<Integer, String>build()); for (MutableNetwork<Integer, String> network : testNetworks) { network.addEdge(1, 2, "1-2"); EndpointPair<Integer> endpointPair = network.incidentNodes("1-2"); try { endpointPair.adjacentNode(3); fail("Should have rejected adjacentNode() called with a node not incident to edge."); } catch (IllegalArgumentException expected) { } } }
@Test public void testCreateSchema() { assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default")); metadata.createSchema(SESSION, "test", ImmutableMap.of()); assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test")); }
@Test public void testIsOriginalOrder() { assertTrue(isOriginalOrder(ImmutableList.of(0, 1, 2, 3, 4))); assertFalse(isOriginalOrder(ImmutableList.of(0, 2, 1, 3, 4))); }
@Test public void testMoreThanThirtyTwoArguments() { List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(20, 2, 13, 33, 40, 9, 14), ImmutableSet.of(28, 4, 5, 29, 31, 10)); List<Long> expectedResults = ImmutableList.of(822283861886L, 995358664191L); for (int groupId = 0; groupId < groupingSetOrdinals.size(); groupId++) { Set<Integer> groupingSet = groupingSetOrdinals.get(groupId); assertEquals(Long.valueOf(calculateGrouping(groupingSet, fortyIntegers)), expectedResults.get(groupId)); } } }
@Test public void testLeftJoinComplementStatsWithNoClauses() { PlanNodeStatsEstimate expected = NORMALIZER.normalize(LEFT_STATS.mapOutputRowCount(rowCount -> 0.0), TYPES); PlanNodeStatsEstimate actual = JOIN_STATS_RULE.calculateJoinComplementStats( Optional.empty(), ImmutableList.of(), LEFT_STATS, RIGHT_STATS, TYPES); assertEquals(actual, expected); }
private List<Object> getSymbolValues(ValuesNode valuesNode, int symbolId, Session session, Type symbolType) { if (UNKNOWN.equals(symbolType)) { // special casing for UNKNOWN as evaluateConstantExpression does not handle that return IntStream.range(0, valuesNode.getRows().size()) .mapToObj(rowId -> null) .collect(toList()); } return valuesNode.getRows().stream() .map(row -> row.get(symbolId)) .map(expression -> evaluateConstantExpression(expression, symbolType, metadata, session, ImmutableList.of())) .collect(toList()); }
@Test public void tableIsCreatedAfterCommits() { assertThatNoTableIsCreated(); SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table"); ConnectorOutputTableHandle table = metadata.beginCreateTable( SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), tableProperties), Optional.empty()); assertThatNoTableIsCreated(); metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of()); List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty()); assertTrue(tables.size() == 1, "Expected only one table."); assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'"); }
/** Regression test for bug found. */ public void testCorrectOrdering_regression() { MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(ImmutableList.of(3, 5, 1, 4, 7)); List<Integer> expected = ImmutableList.of(1, 3, 4, 5, 7); List<Integer> actual = new ArrayList<>(5); for (int i = 0; i < expected.size(); i++) { actual.add(q.pollFirst()); } assertEquals(expected, actual); }