Search in sources :

Example 66 with MutablePair

use of org.apache.commons.lang3.tuple.MutablePair in project hive by apache.

the class DecimalIntervalSplitter method getIntervals.

@Override
public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {
    List<MutablePair<String, String>> intervals = new ArrayList<>();
    DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
    int scale = decimalTypeInfo.getScale();
    BigDecimal decimalLower = new BigDecimal(lowerBound);
    BigDecimal decimalUpper = new BigDecimal(upperBound);
    BigDecimal decimalInterval = (decimalUpper.subtract(decimalLower)).divide(new BigDecimal(numPartitions), MathContext.DECIMAL64);
    BigDecimal splitDecimalLower, splitDecimalUpper;
    for (int i = 0; i < numPartitions; i++) {
        splitDecimalLower = decimalLower.add(decimalInterval.multiply(new BigDecimal(i))).setScale(scale, RoundingMode.HALF_EVEN);
        splitDecimalUpper = decimalLower.add(decimalInterval.multiply(new BigDecimal(i + 1))).setScale(scale, RoundingMode.HALF_EVEN);
        if (splitDecimalLower.compareTo(splitDecimalUpper) < 0) {
            intervals.add(new MutablePair<String, String>(splitDecimalLower.toPlainString(), splitDecimalUpper.toPlainString()));
        }
    }
    return intervals;
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) MutablePair(org.apache.commons.lang3.tuple.MutablePair) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 67 with MutablePair

use of org.apache.commons.lang3.tuple.MutablePair in project hive by apache.

the class HiveKVResultCache method next.

public synchronized Tuple2<HiveKey, BytesWritable> next() {
    Preconditions.checkState(hasNext());
    if (!readBufferUsed) {
        try {
            if (input == null && output != null) {
                // Close output stream if open
                output.close();
                output = null;
                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(tmpFile);
                    input = new Input(fis);
                } finally {
                    if (input == null && fis != null) {
                        fis.close();
                    }
                }
            }
            if (input != null) {
                // Load next batch from disk
                for (int i = 0; i < IN_MEMORY_NUM_ROWS; i++) {
                    MutablePair<HiveKey, BytesWritable> pair = readBuffer[i];
                    pair.setLeft(readHiveKey(input));
                    pair.setRight(readValue(input));
                }
                if (input.end()) {
                    input.close();
                    input = null;
                }
                rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
                readBufferUsed = true;
                readCursor = 0;
            } else if (writeCursor == 1) {
                MutablePair<HiveKey, BytesWritable> pair = writeBuffer[0];
                Tuple2<HiveKey, BytesWritable> row = new Tuple2<HiveKey, BytesWritable>(pair.getLeft(), pair.getRight());
                pair.setLeft(null);
                pair.setRight(null);
                writeCursor = 0;
                return row;
            } else {
                // No record on disk, more data in write buffer
                switchBufferAndResetCursor();
            }
        } catch (Exception e) {
            // Clean up the cache
            clear();
            throw new RuntimeException("Failed to load rows from disk", e);
        }
    }
    MutablePair<HiveKey, BytesWritable> pair = readBuffer[readCursor];
    Tuple2<HiveKey, BytesWritable> row = new Tuple2<HiveKey, BytesWritable>(pair.getLeft(), pair.getRight());
    pair.setLeft(null);
    pair.setRight(null);
    if (++readCursor >= rowsInReadBuffer) {
        readBufferUsed = false;
        rowsInReadBuffer = 0;
        readCursor = 0;
    }
    return row;
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) Input(com.esotericsoftware.kryo.io.Input) HiveKey(org.apache.hadoop.hive.ql.io.HiveKey) Tuple2(scala.Tuple2) BytesWritable(org.apache.hadoop.io.BytesWritable) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

MutablePair (org.apache.commons.lang3.tuple.MutablePair)67 Pair (org.apache.commons.lang3.tuple.Pair)33 Test (org.junit.Test)28 Message (com.microsoft.azure.sdk.iot.device.Message)27 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)27 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)23 HashMap (java.util.HashMap)18 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)17 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 AreaId (bwem.area.typedef.AreaId)7 List (java.util.List)7 Map (java.util.Map)6 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)5 MiniTile (bwem.tile.MiniTile)4 Altitude (bwem.typedef.Altitude)4 ContainerStartRequest (com.datatorrent.stram.StreamingContainerAgent.ContainerStartRequest)4 ContainerRequest (org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest)4 WalkPosition (org.openbw.bwapi4j.WalkPosition)4