Search in sources :

Example 91 with Set

use of java.util.Set in project hive by apache.

the class TestVectorGroupByOperator method testAggregateLongKeyIterable.

public void testAggregateLongKeyIterable(String aggregateName, Iterable<VectorizedRowBatch> data, HashMap<Object, Object> expected) throws HiveException {
    List<String> mapColumnNames = new ArrayList<String>();
    mapColumnNames.add("Key");
    mapColumnNames.add("Value");
    VectorizationContext ctx = new VectorizationContext("name", mapColumnNames);
    Set<Object> keys = new HashSet<Object>();
    GroupByDesc desc = buildKeyGroupByDesc(ctx, aggregateName, "Value", TypeInfoFactory.longTypeInfo, "Key", TypeInfoFactory.longTypeInfo);
    CompilationOpContext cCtx = new CompilationOpContext();
    Operator<? extends OperatorDesc> groupByOp = OperatorFactory.get(cCtx, desc);
    VectorGroupByOperator vgo = (VectorGroupByOperator) Vectorizer.vectorizeGroupByOperator(groupByOp, ctx);
    FakeCaptureOutputOperator out = FakeCaptureOutputOperator.addCaptureOutputChild(cCtx, vgo);
    vgo.initialize(hconf, null);
    out.setOutputInspector(new FakeCaptureOutputOperator.OutputInspector() {

        private String aggregateName;

        private HashMap<Object, Object> expected;

        private Set<Object> keys;

        @Override
        public void inspectRow(Object row, int tag) throws HiveException {
            assertTrue(row instanceof Object[]);
            Object[] fields = (Object[]) row;
            assertEquals(2, fields.length);
            Object key = fields[0];
            Long keyValue = null;
            if (null != key) {
                assertTrue(key instanceof LongWritable);
                LongWritable lwKey = (LongWritable) key;
                keyValue = lwKey.get();
            }
            assertTrue(expected.containsKey(keyValue));
            String keyAsString = String.format("%s", key);
            Object expectedValue = expected.get(keyValue);
            Object value = fields[1];
            Validator validator = getValidator(aggregateName);
            validator.validate(keyAsString, expectedValue, new Object[] { value });
            keys.add(keyValue);
        }

        private FakeCaptureOutputOperator.OutputInspector init(String aggregateName, HashMap<Object, Object> expected, Set<Object> keys) {
            this.aggregateName = aggregateName;
            this.expected = expected;
            this.keys = keys;
            return this;
        }
    }.init(aggregateName, expected, keys));
    for (VectorizedRowBatch unit : data) {
        vgo.process(unit, 0);
    }
    vgo.close(false);
    List<Object> outBatchList = out.getCapturedRows();
    assertNotNull(outBatchList);
    assertEquals(expected.size(), outBatchList.size());
    assertEquals(expected.size(), keys.size());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompilationOpContext(org.apache.hadoop.hive.ql.CompilationOpContext) LongWritable(org.apache.hadoop.io.LongWritable) VectorGroupByDesc(org.apache.hadoop.hive.ql.plan.VectorGroupByDesc) GroupByDesc(org.apache.hadoop.hive.ql.plan.GroupByDesc) HashSet(java.util.HashSet) FakeCaptureOutputOperator(org.apache.hadoop.hive.ql.exec.vector.util.FakeCaptureOutputOperator)

Example 92 with Set

use of java.util.Set in project hive by apache.

the class TestVectorGroupByOperator method testKeyTypeAggregate.

private void testKeyTypeAggregate(String aggregateName, FakeVectorRowBatchFromObjectIterables data, Map<Object, Object> expected) throws HiveException {
    List<String> mapColumnNames = new ArrayList<String>();
    mapColumnNames.add("Key");
    mapColumnNames.add("Value");
    VectorizationContext ctx = new VectorizationContext("name", mapColumnNames);
    Set<Object> keys = new HashSet<Object>();
    AggregationDesc agg = buildAggregationDesc(ctx, aggregateName, GenericUDAFEvaluator.Mode.PARTIAL1, "Value", TypeInfoFactory.getPrimitiveTypeInfo(data.getTypes()[1]));
    ArrayList<AggregationDesc> aggs = new ArrayList<AggregationDesc>();
    aggs.add(agg);
    ArrayList<String> outputColumnNames = new ArrayList<String>();
    outputColumnNames.add("_col0");
    outputColumnNames.add("_col1");
    GroupByDesc desc = new GroupByDesc();
    desc.setVectorDesc(new VectorGroupByDesc());
    desc.setOutputColumnNames(outputColumnNames);
    desc.setAggregators(aggs);
    ((VectorGroupByDesc) desc.getVectorDesc()).setProcessingMode(ProcessingMode.HASH);
    ExprNodeDesc keyExp = buildColumnDesc(ctx, "Key", TypeInfoFactory.getPrimitiveTypeInfo(data.getTypes()[0]));
    ArrayList<ExprNodeDesc> keysDesc = new ArrayList<ExprNodeDesc>();
    keysDesc.add(keyExp);
    desc.setKeys(keysDesc);
    CompilationOpContext cCtx = new CompilationOpContext();
    Operator<? extends OperatorDesc> groupByOp = OperatorFactory.get(cCtx, desc);
    VectorGroupByOperator vgo = (VectorGroupByOperator) Vectorizer.vectorizeGroupByOperator(groupByOp, ctx);
    FakeCaptureOutputOperator out = FakeCaptureOutputOperator.addCaptureOutputChild(cCtx, vgo);
    vgo.initialize(hconf, null);
    out.setOutputInspector(new FakeCaptureOutputOperator.OutputInspector() {

        private int rowIndex;

        private String aggregateName;

        private Map<Object, Object> expected;

        private Set<Object> keys;

        @Override
        public void inspectRow(Object row, int tag) throws HiveException {
            assertTrue(row instanceof Object[]);
            Object[] fields = (Object[]) row;
            assertEquals(2, fields.length);
            Object key = fields[0];
            Object keyValue = null;
            if (null == key) {
                keyValue = null;
            } else if (key instanceof ByteWritable) {
                ByteWritable bwKey = (ByteWritable) key;
                keyValue = bwKey.get();
            } else if (key instanceof ShortWritable) {
                ShortWritable swKey = (ShortWritable) key;
                keyValue = swKey.get();
            } else if (key instanceof IntWritable) {
                IntWritable iwKey = (IntWritable) key;
                keyValue = iwKey.get();
            } else if (key instanceof LongWritable) {
                LongWritable lwKey = (LongWritable) key;
                keyValue = lwKey.get();
            } else if (key instanceof TimestampWritable) {
                TimestampWritable twKey = (TimestampWritable) key;
                keyValue = twKey.getTimestamp();
            } else if (key instanceof DoubleWritable) {
                DoubleWritable dwKey = (DoubleWritable) key;
                keyValue = dwKey.get();
            } else if (key instanceof FloatWritable) {
                FloatWritable fwKey = (FloatWritable) key;
                keyValue = fwKey.get();
            } else if (key instanceof BooleanWritable) {
                BooleanWritable bwKey = (BooleanWritable) key;
                keyValue = bwKey.get();
            } else if (key instanceof HiveDecimalWritable) {
                HiveDecimalWritable hdwKey = (HiveDecimalWritable) key;
                keyValue = hdwKey.getHiveDecimal();
            } else {
                Assert.fail(String.format("Not implemented key output type %s: %s", key.getClass().getName(), key));
            }
            String keyValueAsString = String.format("%s", keyValue);
            assertTrue(expected.containsKey(keyValue));
            Object expectedValue = expected.get(keyValue);
            Object value = fields[1];
            Validator validator = getValidator(aggregateName);
            validator.validate(keyValueAsString, expectedValue, new Object[] { value });
            keys.add(keyValue);
        }

        private FakeCaptureOutputOperator.OutputInspector init(String aggregateName, Map<Object, Object> expected, Set<Object> keys) {
            this.aggregateName = aggregateName;
            this.expected = expected;
            this.keys = keys;
            return this;
        }
    }.init(aggregateName, expected, keys));
    for (VectorizedRowBatch unit : data) {
        vgo.process(unit, 0);
    }
    vgo.close(false);
    List<Object> outBatchList = out.getCapturedRows();
    assertNotNull(outBatchList);
    assertEquals(expected.size(), outBatchList.size());
    assertEquals(expected.size(), keys.size());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) LongWritable(org.apache.hadoop.io.LongWritable) VectorGroupByDesc(org.apache.hadoop.hive.ql.plan.VectorGroupByDesc) GroupByDesc(org.apache.hadoop.hive.ql.plan.GroupByDesc) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) HashSet(java.util.HashSet) FakeCaptureOutputOperator(org.apache.hadoop.hive.ql.exec.vector.util.FakeCaptureOutputOperator) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) CompilationOpContext(org.apache.hadoop.hive.ql.CompilationOpContext) VectorGroupByDesc(org.apache.hadoop.hive.ql.plan.VectorGroupByDesc) AggregationDesc(org.apache.hadoop.hive.ql.plan.AggregationDesc) Map(java.util.Map) HashMap(java.util.HashMap)

Example 93 with Set

use of java.util.Set in project hive by apache.

the class TestCloudExecutionContextProvider method testRetry.

@org.junit.Test
public void testRetry() throws Exception {
    when(cloudComputeService.createNodes(anyInt())).then(new Answer<Set<NodeMetadata>>() {

        int count = 0;

        @Override
        public Set<NodeMetadata> answer(InvocationOnMock invocation) throws Throwable {
            if (count++ == 0) {
                throw runNodesException;
            }
            return Collections.singleton(node3);
        }
    });
    CloudExecutionContextProvider provider = new CloudExecutionContextProvider(dataDir, NUM_NODES, cloudComputeService, sshCommandExecutor, workingDir, PRIVATE_KEY, USER, SLAVE_DIRS, 1, 0, 1);
    ExecutionContext executionContext = provider.createExecutionContext();
    Set<String> hosts = Sets.newHashSet();
    for (Host host : executionContext.getHosts()) {
        hosts.add(host.getName());
    }
    Assert.assertEquals(Sets.newHashSet("1.1.1.1", "1.1.1.3"), hosts);
}
Also used : Set(java.util.Set) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Host(org.apache.hive.ptest.execution.conf.Host)

Example 94 with Set

use of java.util.Set in project kafka by apache.

the class AssignmentInfo method encode.

/**
     * @throws TaskAssignmentException if method fails to encode the data, e.g., if there is an
     * IO exception during encoding
     */
public ByteBuffer encode() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    try {
        // Encode version
        out.writeInt(version);
        // Encode active tasks
        out.writeInt(activeTasks.size());
        for (TaskId id : activeTasks) {
            id.writeTo(out);
        }
        // Encode standby tasks
        out.writeInt(standbyTasks.size());
        for (Map.Entry<TaskId, Set<TopicPartition>> entry : standbyTasks.entrySet()) {
            TaskId id = entry.getKey();
            id.writeTo(out);
            Set<TopicPartition> partitions = entry.getValue();
            writeTopicPartitions(out, partitions);
        }
        out.writeInt(partitionsByHost.size());
        for (Map.Entry<HostInfo, Set<TopicPartition>> entry : partitionsByHost.entrySet()) {
            final HostInfo hostInfo = entry.getKey();
            out.writeUTF(hostInfo.host());
            out.writeInt(hostInfo.port());
            writeTopicPartitions(out, entry.getValue());
        }
        out.flush();
        out.close();
        return ByteBuffer.wrap(baos.toByteArray());
    } catch (IOException ex) {
        throw new TaskAssignmentException("Failed to encode AssignmentInfo", ex);
    }
}
Also used : TaskAssignmentException(org.apache.kafka.streams.errors.TaskAssignmentException) TaskId(org.apache.kafka.streams.processor.TaskId) Set(java.util.Set) HashSet(java.util.HashSet) DataOutputStream(java.io.DataOutputStream) TopicPartition(org.apache.kafka.common.TopicPartition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) HostInfo(org.apache.kafka.streams.state.HostInfo)

Example 95 with Set

use of java.util.Set in project kafka by apache.

the class AssignmentInfo method decode.

/**
     * @throws TaskAssignmentException if method fails to decode the data or if the data version is unknown
     */
public static AssignmentInfo decode(ByteBuffer data) {
    // ensure we are at the beginning of the ByteBuffer
    data.rewind();
    DataInputStream in = new DataInputStream(new ByteBufferInputStream(data));
    try {
        // Decode version
        int version = in.readInt();
        if (version < 0 || version > CURRENT_VERSION) {
            TaskAssignmentException ex = new TaskAssignmentException("Unknown assignment data version: " + version);
            log.error(ex.getMessage(), ex);
            throw ex;
        }
        // Decode active tasks
        int count = in.readInt();
        List<TaskId> activeTasks = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            activeTasks.add(TaskId.readFrom(in));
        }
        // Decode standby tasks
        count = in.readInt();
        Map<TaskId, Set<TopicPartition>> standbyTasks = new HashMap<>(count);
        for (int i = 0; i < count; i++) {
            TaskId id = TaskId.readFrom(in);
            standbyTasks.put(id, readTopicPartitions(in));
        }
        Map<HostInfo, Set<TopicPartition>> hostStateToTopicPartitions = new HashMap<>();
        if (version == CURRENT_VERSION) {
            int numEntries = in.readInt();
            for (int i = 0; i < numEntries; i++) {
                HostInfo hostInfo = new HostInfo(in.readUTF(), in.readInt());
                hostStateToTopicPartitions.put(hostInfo, readTopicPartitions(in));
            }
        }
        return new AssignmentInfo(activeTasks, standbyTasks, hostStateToTopicPartitions);
    } catch (IOException ex) {
        throw new TaskAssignmentException("Failed to decode AssignmentInfo", ex);
    }
}
Also used : TaskAssignmentException(org.apache.kafka.streams.errors.TaskAssignmentException) TaskId(org.apache.kafka.streams.processor.TaskId) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ByteBufferInputStream(org.apache.kafka.common.utils.ByteBufferInputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) HostInfo(org.apache.kafka.streams.state.HostInfo)

Aggregations

Set (java.util.Set)6789 HashSet (java.util.HashSet)4372 HashMap (java.util.HashMap)2090 Map (java.util.Map)1865 Iterator (java.util.Iterator)1774 ArrayList (java.util.ArrayList)1113 List (java.util.List)980 Test (org.junit.Test)920 TreeSet (java.util.TreeSet)536 IOException (java.io.IOException)501 SSOException (com.iplanet.sso.SSOException)467 LinkedHashSet (java.util.LinkedHashSet)418 SMSException (com.sun.identity.sm.SMSException)347 IdRepoException (com.sun.identity.idm.IdRepoException)268 Collection (java.util.Collection)259 ImmutableSet (com.google.common.collect.ImmutableSet)256 File (java.io.File)245 SSOToken (com.iplanet.sso.SSOToken)226 Collectors (java.util.stream.Collectors)219 Test (org.testng.annotations.Test)209