Example usage for org.apache.cassandra.utils Pair create

List of usage examples for org.apache.cassandra.utils Pair create

Introduction

In this page you can find the example usage for org.apache.cassandra.utils Pair create.

Prototype

public static <X, Y> Pair<X, Y> create(X x, Y y) 

Source Link

Usage

From source file:com.dell.doradus.service.rest.RESTServlet.java

License:Apache License

private Pair<String, String> extractParam(String part) {
    int eqInx = part.indexOf('=');
    String paramName;/*from w w  w  .ja  va 2 s . c  o  m*/
    String paramValue;
    if (eqInx < 0) {
        paramName = part;
        paramValue = null;
    } else {
        paramName = part.substring(0, eqInx);
        paramValue = part.substring(eqInx + 1);
    }
    return Pair.create(paramName, paramValue);
}

From source file:com.dell.doradus.service.spider.SpiderService.java

License:Apache License

private Pair<String, String> extractLinkValue(TableDefinition tableDef, String colName) {
    if (colName.length() < 3 || colName.charAt(0) != '~') {
        return null;
    }//  ww  w .  j av  a 2s .  c  o m

    // A '/' should separate the field name and object ID value. Example: ~foo/xyz
    int slashInx = 1;
    while (slashInx < colName.length() && colName.charAt(slashInx) != '/') {
        slashInx++;
    }
    if (slashInx >= colName.length()) {
        return null;
    }
    String fieldName = colName.substring(1, slashInx);
    String objID = colName.substring(slashInx + 1);
    return Pair.create(fieldName, objID);
}

From source file:com.fullcontact.cassandra.io.sstable.Component.java

License:Apache License

/**
 * Filename of the form "<ksname>/<cfname>-[tmp-][<version>-]<gen>-<component>",
 *
 * @return A Descriptor for the SSTable, and a Component for this particular file.
 *         TODO move descriptor into Component field
 *//*from   ww w.  ja  v a 2s.  c  o m*/
public static Pair<Descriptor, Component> fromFilename(Path directory, String name, FileSystem fs) {
    Pair<Descriptor, String> path = Descriptor.fromFilename(directory, name);

    // parse the component suffix
    Type type = Type.fromRepresentation(path.right);
    // build (or retrieve singleton for) the component object
    Component component;
    switch (type) {
    case DATA:
        component = Component.DATA;
        break;
    case PRIMARY_INDEX:
        component = Component.PRIMARY_INDEX;
        break;
    case FILTER:
        component = Component.FILTER;
        break;
    case COMPACTED_MARKER:
        component = Component.COMPACTED_MARKER;
        break;
    case COMPRESSION_INFO:
        component = Component.COMPRESSION_INFO;
        break;
    case STATS:
        component = Component.STATS;
        break;
    case DIGEST:
        component = Component.DIGEST;
        break;
    case SUMMARY:
        component = Component.SUMMARY;
        break;
    case TOC:
        component = Component.TOC;
        break;
    case CUSTOM:
        component = new Component(Type.CUSTOM, path.right);
        break;
    default:
        throw new IllegalStateException();
    }

    return Pair.create(path.left, component);
}

From source file:com.fullcontact.cassandra.io.sstable.Descriptor.java

License:Apache License

/**
 * Filename of the form "<ksname>-<cfname>-[tmp-][<version>-]<gen>-<component>"
 *
 * @param directory The directory of the SSTable files
 * @param name      The name of the SSTable file
 * @return A Descriptor for the SSTable, and the Component remainder.
 *//*from  w  w  w.  j  ava 2  s.  com*/
public static Pair<Descriptor, String> fromFilename(Path directory, String name) {
    // tokenize the filename
    StringTokenizer st = new StringTokenizer(name, String.valueOf(separator));
    String nexttok;

    // all filenames must start with keyspace and column family
    String ksname = st.nextToken();
    String cfname = st.nextToken();

    // optional temporary marker
    nexttok = st.nextToken();
    boolean temporary = false;
    if (nexttok.equals(SSTable.TEMPFILE_MARKER)) {
        temporary = true;
        nexttok = st.nextToken();
    }

    // optional version string
    Version version = Version.LEGACY;
    if (Version.validate(nexttok)) {
        version = new Version(nexttok);
        nexttok = st.nextToken();
    }
    int generation = Integer.parseInt(nexttok);

    // component suffix
    String component = st.nextToken();
    directory = directory != null ? directory : new Path(".");
    return Pair.create(new Descriptor(version, directory, ksname, cfname, generation, temporary), component);
}

From source file:com.jeffjirsa.cassandra.db.compaction.SizeTieredCompactionStrategy.java

License:Apache License

/**
 * Returns a (bucket, hotness) pair or null if there were not enough sstables in the bucket to meet minThreshold.
 * If there are more than maxThreshold sstables, the coldest sstables will be trimmed to meet the threshold.
 **/// w  w  w  . j a  v  a  2 s . c om
@VisibleForTesting
static Pair<List<SSTableReader>, Double> trimToThresholdWithHotness(List<SSTableReader> bucket,
        int maxThreshold) {
    // Sort by sstable hotness (descending). We first build a map because the hotness may change during the sort.
    final Map<SSTableReader, Double> hotnessSnapshot = getHotnessMap(bucket);
    Collections.sort(bucket, new Comparator<SSTableReader>() {
        public int compare(SSTableReader o1, SSTableReader o2) {
            return -1 * Double.compare(hotnessSnapshot.get(o1), hotnessSnapshot.get(o2));
        }
    });

    // and then trim the coldest sstables off the end to meet the maxThreshold
    List<SSTableReader> prunedBucket = bucket.subList(0, Math.min(bucket.size(), maxThreshold));

    // bucket hotness is the sum of the hotness of all sstable members
    double bucketHotness = 0.0;
    for (SSTableReader sstr : prunedBucket)
        bucketHotness += hotness(sstr);

    return Pair.create(prunedBucket, bucketHotness);
}

From source file:com.jeffjirsa.cassandra.db.compaction.SizeTieredCompactionStrategy.java

License:Apache License

public static List<Pair<SSTableReader, Long>> createSSTableAndLengthPairs(Iterable<SSTableReader> sstables) {
    List<Pair<SSTableReader, Long>> sstableLengthPairs = new ArrayList<>(Iterables.size(sstables));
    for (SSTableReader sstable : sstables)
        sstableLengthPairs.add(Pair.create(sstable, sstable.onDiskLength()));
    return sstableLengthPairs;
}

From source file:com.jeffjirsa.cassandra.db.compaction.TimeWindowCompactionStrategy.java

License:Apache License

/**
 * Find the lowest and highest timestamps in a given timestamp/unit pair
 * Returns milliseconds, caller should adjust accordingly
 *///from w  w  w.ja v  a  2s .c  o m
public static Pair<Long, Long> getWindowBoundsInMillis(TimeUnit windowTimeUnit, int windowTimeSize,
        long timestampInMillis) {
    long lowerTimestamp;
    long upperTimestamp;
    long timestampInSeconds = timestampInMillis / 1000L;

    switch (windowTimeUnit) {
    case MINUTES:
        lowerTimestamp = timestampInSeconds - ((timestampInSeconds) % (60 * windowTimeSize));
        upperTimestamp = (lowerTimestamp + (60L * (windowTimeSize - 1L))) + 59L;
        break;
    case HOURS:
        lowerTimestamp = timestampInSeconds - ((timestampInSeconds) % (3600 * windowTimeSize));
        upperTimestamp = (lowerTimestamp + (3600L * (windowTimeSize - 1L))) + 3599L;
        break;
    case DAYS:
    default:
        lowerTimestamp = timestampInSeconds - ((timestampInSeconds) % (86400 * windowTimeSize));
        upperTimestamp = (lowerTimestamp + (86400L * (windowTimeSize - 1L))) + 86399L;
        break;
    }

    return Pair.create(lowerTimestamp * 1000L, upperTimestamp * 1000L);

}

From source file:com.knewton.mapreduce.io.sstable.BackwardsCompatibleDescriptor.java

License:Apache License

/**
 * Implementation of {@link Descriptor#fromFilename(File, String)} that is backwards compatible
 * with older sstables/* www.j a v a  2  s  .c  o m*/
 *
 * @param directory
 * @param name
 * @return A descriptor for the sstable
 */
public static Pair<Descriptor, String> fromFilename(File directory, String name) {
    Iterator<String> iterator = Splitter.on(separator).split(name).iterator();
    iterator.next();
    String tempFlagMaybe = iterator.next();
    String versionMaybe = iterator.next();
    String generationMaybe = iterator.next();
    Pair<Descriptor, String> dsPair;
    if (tempFlagMaybe.equals(SSTable.TEMPFILE_MARKER) && generationMaybe.matches("\\d+")
            && !new Version(versionMaybe).hasAncestors) {
        // old sstable file with temp flag.
        dsPair = Descriptor.fromFilename(directory, directory.getName() + separator + name);
    } else if (versionMaybe.equals(SSTable.TEMPFILE_MARKER)) {
        // new sstable file with temp flag.
        dsPair = Descriptor.fromFilename(directory, name);
    } else if (StringUtils.countMatches(name, String.valueOf(separator)) < NUM_SEPARATORS) {
        // old sstable file with no temp flag.
        dsPair = Descriptor.fromFilename(directory, directory.getName() + separator + name);
    } else {
        // new sstable file with no temp flag.
        dsPair = Descriptor.fromFilename(directory, name);
    }
    // cast so that Pair doens't complain.
    return Pair.create((Descriptor) new BackwardsCompatibleDescriptor(dsPair.left), dsPair.right);
}

From source file:com.netflix.aegisthus.io.sstable.IndexScanner.java

License:Apache License

@Override
public Pair<String, Long> next() {
    try {/*from  w  w  w.  j  ava 2  s.  c o m*/
        String key = BytesType.instance.getString(ByteBufferUtil.readWithShortLength(input));
        Long offset = input.readLong();
        if (version.hasPromotedIndexes) {
            skipPromotedIndexes();
        }
        return Pair.create(key, offset);
    } catch (IOException e) {
        throw new IOError(e);
    }

}

From source file:com.netflix.astyanax.util.CsvColumnReader.java

License:Apache License

@Override
public List<Pair<String, String>> next() throws IOException {
    // Iterate rows
    String[] row = parser.getLine();
    if (null == row)
        return null;

    List<Pair<String, String>> columns = new ArrayList<Pair<String, String>>();
    // Build row mutation for all columns
    columns.add(Pair.create("key", row[0]));
    if (row.length == 3)
        columns.add(Pair.create(row[1], row[2]));
    return columns;
}