private static List<StageCpuDistribution> getCpuDistributions(QueryInfo queryInfo) { if (!queryInfo.getOutputStage().isPresent()) { return ImmutableList.of(); } ImmutableList.Builder<StageCpuDistribution> builder = ImmutableList.builder(); populateDistribution(queryInfo.getOutputStage().get(), builder); return builder.build(); }
private static ImmutableList<URL> getClassLoaderUrls(ClassLoader classloader) { if (classloader instanceof URLClassLoader) { return ImmutableList.copyOf(((URLClassLoader) classloader).getURLs()); } if (classloader.equals(ClassLoader.getSystemClassLoader())) { return parseJavaClassPath(); } return ImmutableList.of(); }
@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 testWarning() { List<PrestoWarning> warnings = createTestWarnings(3); List<WarningCode> warningCodes = warnings.stream() .map(PrestoWarning::getWarningCode) .collect(toImmutableList()); assertPlannerWarnings(queryRunner, "SELECT * FROM NATION", ImmutableMap.of(), warningCodes, Optional.of(ImmutableList.of(new TestWarningsRule(warnings)))); }
@Test public void testTypes() { GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] {0}, Optional.of(1), 100, JOIN_COMPILER); // Additional bigint channel for hash assertEquals(groupByHash.getTypes(), ImmutableList.of(VARCHAR, BIGINT)); }
private boolean hasAggregates(QuerySpecification node) { ImmutableList.Builder<Node> toExtractBuilder = ImmutableList.builder(); toExtractBuilder.addAll(node.getSelect().getSelectItems().stream() .filter(SingleColumn.class::isInstance) .collect(toImmutableList())); toExtractBuilder.addAll(getSortItemsFromOrderBy(node.getOrderBy())); node.getHaving().ifPresent(toExtractBuilder::add); List<FunctionCall> aggregates = extractAggregateFunctions(toExtractBuilder.build(), metadata.getFunctionRegistry()); return !aggregates.isEmpty(); }
@Test public void testContainsWithEquiClause() { assertPlan("SELECT b.name, a.name " + "FROM " + POINTS_SQL + ", " + POLYGONS_SQL + " " + "WHERE a.name = b.name AND ST_Contains(ST_GeometryFromText(wkt), ST_Point(lng, lat))", anyTree( join(JoinNode.Type.INNER, ImmutableList.of(equiJoinClause("name_a", "name_b")), Optional.of("ST_Contains(ST_GeometryFromText(cast(wkt as varchar)), ST_Point(lng, lat))"), anyTree(values(ImmutableMap.of("lng", 0, "lat", 1, "name_a", 2))), anyTree(values(ImmutableMap.of("wkt", 0, "name_b", 1)))))); }
@Test public void testProjectNoColumns() { PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(), OptionalInt.of(MAX_BATCH_SIZE)); Page inputPage = new Page(createLongSequenceBlock(0, 100)); Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage); List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 1); Page outputPage = outputPages.get(0).orElse(null); assertEquals(outputPage.getChannelCount(), 0); assertEquals(outputPage.getPositionCount(), inputPage.getPositionCount()); }
@Override protected Boolean visitIfExpression(IfExpression node, Void context) { ImmutableList.Builder<Expression> expressions = ImmutableList.<Expression>builder() .add(node.getCondition()) .add(node.getTrueValue()); if (node.getFalseValue().isPresent()) { expressions.add(node.getFalseValue().get()); } return expressions.build().stream().allMatch(expression -> process(expression, context)); }
@Test public void testInvalidGetPartitionNames() { assertEquals(metastore.getPartitionNames(BAD_DATABASE, TEST_TABLE).get(), ImmutableList.of()); }
@Test public void testNoCaching() { ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); ArrayType arrayType = new ArrayType(VARCHAR); Signature signature = new Signature("concat", SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature(), arrayType.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(field(0, arrayType), field(1, arrayType)))); ImmutableList<RowExpression> projections = projectionsBuilder.build(); PageProcessor pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); PageProcessor pageProcessor2 = compiler.compilePageProcessor(Optional.empty(), projections).get(); assertTrue(pageProcessor != pageProcessor2); }
@Test public void testCreateOnlyNullsPredicate() { ImmutableList.Builder<HivePartition> partitions = ImmutableList.builder(); for (int i = 0; i < 5; i++) { partitions.add(new HivePartition( new SchemaTableName("test", "test"), Integer.toString(i), ImmutableMap.of(TEST_COLUMN_HANDLE, NullableValue.asNull(VarcharType.VARCHAR)))); } createPredicate(ImmutableList.of(TEST_COLUMN_HANDLE), partitions.build()); }
public void testToMapWithDuplicateKeys() { Iterable<String> strings = ImmutableList.of("one", "two", "three", "two", "one"); ImmutableMap<String, Integer> map = Maps.toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) .inOrder(); }
public void testAsList() { ImmutableList<Integer> list = ContiguousSet.create(Range.closed(1, 3), integers()).asList(); for (int i = 0; i < 3; i++) { assertEquals(i + 1, list.get(i).intValue()); } assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.iterator())); assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.toArray(new Integer[0]))); }
@Override public synchronized Optional<List<String>> getAllTables(String databaseName) { ImmutableList.Builder<String> tables = ImmutableList.builder(); for (SchemaTableName schemaTableName : this.relations.keySet()) { if (schemaTableName.getSchemaName().equals(databaseName)) { tables.add(schemaTableName.getTableName()); } } return Optional.of(tables.build()); }