Example usage for org.apache.commons.lang3.tuple Triple getRight

List of usage examples for org.apache.commons.lang3.tuple Triple getRight

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Triple getRight.

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this triple.

Usage

From source file:org.verdictdb.coordinator.SelectQueryCoordinator.java

private void ensureScrambleCorrectnessInner(SelectQuery query, BaseColumn countDistinctColumn)
        throws VerdictDBException {

    Triple<Boolean, Boolean, BaseColumn> inspectionInfo = inspectAggregatesInSelectList(query);
    boolean containAggregateItem = inspectionInfo.getLeft();
    boolean containCountDistinctItem = inspectionInfo.getMiddle();
    countDistinctColumn = inspectionInfo.getRight();

    // check from list
    for (AbstractRelation table : query.getFromList()) {
        if (table instanceof BaseTable) {
            String schemaName = ((BaseTable) table).getSchemaName();
            String tableName = ((BaseTable) table).getTableName();
            if (!scrambleMetaSet.isScrambled(schemaName, tableName)) {
                continue;
            }/*w w w . jav a 2s . c om*/
            String method = scrambleMetaSet.getScramblingMethod(schemaName, tableName);

            if (containAggregateItem) {
                if (!method.equalsIgnoreCase("uniform") && !method.equalsIgnoreCase("fastconverge")) {
                    throw new VerdictDBValueException(
                            "Simple aggregates must be used with a uniform scramble.");
                }
            } else if (containCountDistinctItem) {
                String hashColumn = scrambleMetaSet.getHashColumn(schemaName, tableName);
                if (!method.equalsIgnoreCase("hash") || hashColumn == null
                        || !hashColumn.equalsIgnoreCase(countDistinctColumn.getColumnName())) {
                    throw new VerdictDBValueException(
                            "Count distinct of a column must be used with the hash scramble "
                                    + "built on that column.");
                }
            }

        } else if (table instanceof JoinTable) {
            for (AbstractRelation jointable : ((JoinTable) table).getJoinList()) {
                if (jointable instanceof SelectQuery) {
                    ensureQuerySupport((SelectQuery) jointable);
                }
            }
        } else if (table instanceof SelectQuery) {
            ensureScrambleCorrectnessInner((SelectQuery) table, countDistinctColumn);
        }
    }
}

From source file:org.verdictdb.core.querying.ola.AsyncAggExecutionNode.java

/**
 * A factory method for AsyncAggExecutionNode.
 *
 * <p>This static method performs the following operations: 1. Link individual aggregate nodes and
 * combiners appropriately. 2. Create a base table which includes several placeholders - scale
 * factor placeholder - temp table placeholder
 *
 * @param idCreator//from   w w w  .  j  av a2s .c  o m
 * @param aggblocks
 * @param combiners
 * @param meta
 * @param aggNodeBlock
 * @return
 */
public static AsyncAggExecutionNode create(IdCreator idCreator, List<AggExecutionNodeBlock> aggblocks,
        List<ExecutableNodeBase> combiners, ScrambleMetaSet meta, AggExecutionNodeBlock aggNodeBlock) {

    AsyncAggExecutionNode node = new AsyncAggExecutionNode(idCreator);

    // this placeholder base table is used for query construction later
    String alias = INNER_RAW_AGG_TABLE_ALIAS;
    Pair<BaseTable, SubscriptionTicket> tableAndTicket = node.createPlaceHolderTable(alias);
    BaseTable placeholderTable = tableAndTicket.getLeft();
    SubscriptionTicket ticket = tableAndTicket.getRight();

    // first agg -> root
    AggExecutionNode firstSource = (AggExecutionNode) aggblocks.get(0).getBlockRootNode();
    firstSource.registerSubscriber(ticket);
    //    node.subscribeTo(individualAggs.get(0), 0);

    // combiners -> root
    for (ExecutableNodeBase c : combiners) {
        c.registerSubscriber(ticket);
        //      node.subscribeTo(c, 0);
    }

    // FOR PARALLEL PROCESSING; we disable this.
    // make the leaf nodes dependent on the aggroot of the previous iteration
    // this will make all the operations on the (i+1)-th block performed after the operations
    // on the i-th block.
    //    for (int i = 0; i < aggblocks.size(); i++) {
    //      if (i > 0) {
    //        AggExecutionNodeBlock aggblock = aggblocks.get(i);
    //        List<ExecutableNodeBase> leafNodes = aggblock.getLeafNodes();
    //        ExecutableNodeBase prevAggRoot = aggblocks.get(i - 1).getBlockRootNode();
    //        for (ExecutableNodeBase leaf : leafNodes) {
    //          leaf.subscribeTo(prevAggRoot, prevAggRoot.getId());
    //        }
    //      }
    //    }

    //    // agg -> next agg (to enfore the execution order)
    //    for (int i = 0; i < individualAggs.size()-1; i++) {
    //      AggExecutionNode thisNode = (AggExecutionNode) individualAggs.get(i);
    //      AggExecutionNode nextNode = (AggExecutionNode) individualAggs.get(i+1);
    //      int channel = thisNode.getId();
    //      nextNode.subscribeTo(thisNode, channel);
    //    }

    node.setScrambleMetaSet(meta); // the scramble meta must be not be shared; thus, thread-safe
    node.setNamer(idCreator); // the name can be shared

    // creates a base query that contain placeholders
    AggMeta sourceAggMeta = firstSource.getAggMeta();
    List<SelectItem> sourceSelectList = firstSource.getSelectQuery().getSelectList();
    Triple<List<ColumnOp>, SqlConvertible, Map<Integer, String>> aggColumnsAndQuery = createBaseQueryForReplacement(
            sourceAggMeta, sourceSelectList, placeholderTable, meta);
    node.aggColumns = aggColumnsAndQuery.getLeft();
    SelectQuery subquery = (SelectQuery) aggColumnsAndQuery.getMiddle();
    Pair<SelectQuery, HashMap<String, UnnamedColumn>> pair = sumUpTierGroup(subquery, sourceAggMeta);
    node.selectQuery = pair.getLeft();
    node.aggContents = pair.getRight();
    node.scrambledTableTierInfo = new ImmutableMap.Builder<Integer, String>()
            .putAll(aggColumnsAndQuery.getRight()).build();

    // add (1) order-by, (2) limit, (3) having clauses to the select query
    QueryNodeBase aggRoot = (QueryNodeBase) aggNodeBlock.getBlockRootNode();
    SelectQuery originalAggQuery = aggRoot.getSelectQuery();

    //    int orderByCount = 0;
    //    for (OrderbyAttribute orderBy : originalAggQuery.getOrderby()) {
    //      String aliasName = ORDER_BY_ALIAS + (orderByCount++);
    //      //      if (orderBy.getAttribute() instanceof AliasedColumn) {
    //      //        aliasName = ((AliasedColumn) orderBy.getAttribute()).getAliasName();
    //      //      } else if (orderBy.getAttribute() instanceof AliasReference) {
    //      //        aliasName = ((AliasReference) orderBy.getAttribute()).getAliasName();
    //      //      } else {
    //      //        // TODO
    //      //        return null;
    //      //      }
    //      BaseColumn col = new BaseColumn(TIER_CONSOLIDATED_TABLE_ALIAS, aliasName);
    //      node.selectQuery.addOrderby(
    //          new OrderbyAttribute(col, orderBy.getOrder(), orderBy.getNullsOrder()));
    //    }

    node.selectQuery.addOrderby(originalAggQuery.getOrderby());

    //    int orderByCount = 0;
    //    for (SelectItem item : node.selectQuery.getSelectList()) {
    //      if (item instanceof AliasedColumn) {
    //        AliasedColumn ac = (AliasedColumn) item;
    //        if (ac.getAliasName().startsWith(AsyncAggExecutionNode.getOrderByAlias())) {
    //          OrderbyAttribute attr = originalAggQuery.getOrderby().get(orderByCount);
    //          BaseColumn col = new BaseColumn(TIER_CONSOLIDATED_TABLE_ALIAS, ac.getAliasName());
    //          node.selectQuery.addOrderby(
    //              new OrderbyAttribute(col, attr.getOrder(), attr.getNullsOrder()));
    //          ++orderByCount;
    //        }
    //      }
    //    }

    if (originalAggQuery.getLimit().isPresent()) {
        node.selectQuery.addLimit(originalAggQuery.getLimit().get());
    }
    if (originalAggQuery.getHaving().isPresent()) {
        node.selectQuery.addHavingByAnd(originalAggQuery.getHaving().get());
    }

    return node;
}

From source file:org.verdictdb.sqlreader.ScrambleTableReplacer.java

private int replaceQuery(SelectQuery query, boolean doReset,
        Triple<Boolean, Boolean, BaseColumn> outerInspectionInfo) throws VerdictDBValueException {
    if (doReset) {
        replaceCount = 0;/*from   ww  w .  j  a va 2s.  c  o m*/
    }

    // check select list
    Triple<Boolean, Boolean, BaseColumn> inspectionInfo = SelectQueryCoordinator
            .inspectAggregatesInSelectList(query);
    boolean containAggregatedItem = inspectionInfo.getLeft();
    boolean containCountDistinctItem = inspectionInfo.getMiddle();
    BaseColumn countDistinctColumn = inspectionInfo.getRight();

    if (containCountDistinctItem && countDistinctColumn == null) {
        throw new VerdictDBValueException(
                "A base column is not found " + "inside the count-distinct function.");
    }

    // this is to handle the case that an outer query includes aggregate functions,
    // the current query is simply a projection.
    if (outerInspectionInfo != null && !containAggregatedItem && !containCountDistinctItem) {
        containAggregatedItem = outerInspectionInfo.getLeft();
        containCountDistinctItem = outerInspectionInfo.getMiddle();
        inspectionInfo = outerInspectionInfo;
    }

    // if both count-distinct and other aggregates appear
    if (containAggregatedItem && containCountDistinctItem) {
        throw new RuntimeException("This line is not supposed to be reached.");
    }
    // if no count-distinct appears and other aggregates appear
    else if (containAggregatedItem) {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            fromList.set(i, replaceTableForSimpleAggregates(fromList.get(i), inspectionInfo));
        }
    }
    // if only count-distinct appears
    else if (containCountDistinctItem) {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            fromList.set(i, replaceTableForCountDistinct(fromList.get(i), inspectionInfo));
        }
    }
    // no aggregate appears; check any subqueries
    else {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            AbstractRelation rel = fromList.get(i);
            if (rel instanceof JoinTable) {
                for (AbstractRelation joined : ((JoinTable) rel).getJoinList()) {
                    if (joined instanceof SelectQuery) {
                        replaceQuery((SelectQuery) joined, false, null);
                    }
                }
            } else if (rel instanceof SelectQuery) {
                replaceQuery((SelectQuery) rel, false, null);
            }
        }
    }

    return replaceCount;
}

From source file:org.verdictdb.sqlreader.ScrambleTableReplacer.java

/**
 * Replaces an original table if there exists a corresponding scramble. Use a hash scramble.
 *
 * @param table/*from w w  w . j  a  v a2s .com*/
 * @return
 * @throws VerdictDBValueException
 */
private AbstractRelation replaceTableForCountDistinct(AbstractRelation table,
        Triple<Boolean, Boolean, BaseColumn> inspectionInfo) throws VerdictDBValueException {

    BaseColumn countDistinctColumn = inspectionInfo.getRight();

    if (table instanceof BaseTable) {
        BaseTable bt = (BaseTable) table;

        for (ScrambleMeta meta : metaSet) {
            // Detects scrambled tables.
            // The scramble meta are expected to be retrieved from the recently created ones.
            if (meta.getSchemaName().equals(bt.getSchemaName()) && meta.getTableName().equals(bt.getTableName())
                    && meta.getMethodWithDefault("uniform").equalsIgnoreCase("hash")
                    && countDistinctColumn.getColumnName().equals(meta.getHashColumn())) {
                ++replaceCount;

                log.info(String.format("Scramble detected: %s.%s", meta.getSchemaName(), meta.getTableName()));

                //          bt.setSchemaName(meta.getSchemaName());
                //          bt.setTableName(meta.getTableName());

                //          log.info(
                //              String.format(
                //                  "Automatic table replacement: %s.%s -> %s.%s",
                //                  meta.getOriginalSchemaName(),
                //                  meta.getOriginalTableName(),
                //                  meta.getSchemaName(),
                //                  meta.getTableName()));

                break;
            } else if (meta.getSchemaName().equals(bt.getSchemaName())
                    && meta.getTableName().equals(bt.getTableName())) {
                // IF the scramble is directly specified.
                ++replaceCount;
            }
        }
    } else if (table instanceof JoinTable) {
        JoinTable jt = (JoinTable) table;
        for (AbstractRelation relation : jt.getJoinList()) {
            this.replaceTableForCountDistinct(relation, inspectionInfo);
        }
    } else if (table instanceof SelectQuery) {
        SelectQuery subquery = (SelectQuery) table;
        this.replaceQuery(subquery, false, inspectionInfo);
    }

    return table;
}

From source file:rapture.plugin.app.FileBasedSandboxLoader.java

@Override
public void loadSandboxFromEntries(String root, String part, PluginSandbox sandbox) throws Exception {
    String area = root + part;/*from w ww. j a  v a  2 s.co  m*/
    System.out.println("From " + area);

    String[] folders = getResourceFolders(area);
    String[] files = getResourceFiles(area);

    for (String f : files) {
        String path = root + part + f;
        Triple<String, String, Scheme> trip = PluginSandboxItem.extractScheme(part + f);
        RaptureURI uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(),
                trip.getRight());
        String fileFullPath = SelfInstaller.class.getResource(path).getPath();
        System.out.println("File " + fileFullPath);
        sandbox.makeItemFromInternalEntry(uri, SelfInstaller.class.getResourceAsStream(path), fileFullPath,
                null);
    }

    for (String f : folders) {
        loadSandboxFromEntries(root, part + f + "/", sandbox);
    }
}

From source file:rapture.plugin.app.JarBasedSandboxLoader.java

@Override
public void loadSandboxFromEntries(String root, String variant, PluginSandbox sandbox) throws Exception {
    String[] files = getResourceFiles(root, variant);

    for (String f : files) {
        boolean isVariant = false;
        String path = "/" + f;
        System.out.println("Path is " + path);
        // remove PLUGIN/
        f = f.substring(7);//from  w w  w. j  a va2 s. c  om
        if (f.startsWith(PluginSandbox.CONTENT)) {
            // remove content/ from filename
            f = f.substring(PluginSandbox.CONTENT.length());
        } else if (f.startsWith(variant + "/")) {
            // remove <variant>/ from filename
            f = f.substring(variant.length() + 1);
            isVariant = true;
        }
        System.out.println("File is " + f);
        Triple<String, String, Scheme> trip = PluginSandboxItem.extractScheme(f);
        System.out.println("Triple is " + trip.toString());

        // Triple is (/curtisweb/,null,blob)
        RaptureURI uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(),
                trip.getRight());
        System.out.println("URI is " + uri.toString());
        sandbox.makeItemFromInternalEntry(uri, SelfInstaller.class.getResourceAsStream(path),
                isVariant ? variant : null);
    }
}

From source file:rapture.plugin.install.PluginSandboxItem.java

public static Pair<RaptureURI, String> calculateURI(String leafTail) {
    String variant = (leafTail.startsWith(CONTENTDIR)) ? null : extractVariant(leafTail);
    Triple<String, String, Scheme> trip = extractScheme(leafTail.substring(variantLength(variant)));
    checkArgument(trip != null, "extraneuous file");
    RaptureURI uri = null;//  w  w  w.jav  a  2 s. c  o m
    switch (trip.getRight()) {
    case USER:
    case ENTITLEMENTGROUP:
        if (trip.getLeft().indexOf("/") == -1) {
            uri = new RaptureURI(trip.getLeft(), trip.getRight());
        }
        break;
    default:
        break;
    }
    if (uri == null) {
        uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(), trip.getRight());
    }
    return new ImmutablePair<RaptureURI, String>(uri, variant);
}

From source file:specminers.referenceparser.graphvizdot.PradelsDotFilesToJffConverter.java

private Document getJffXMLDocument() throws ParserConfigurationException, IOException {
    this.convert();
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    Document doc = docBuilder.newDocument();

    Element structure = doc.createElement("structure");
    doc.appendChild(structure);//from w  w w.j  a v  a2s  .c  o m

    Element type = doc.createElement("type");
    type.setTextContent("fa");
    structure.appendChild(type);

    Element automaton = doc.createElement("automaton");

    for (String stateName : this.stateNames) {
        Element state = doc.createElement("state");
        state.setAttribute("id", stateName);
        state.setAttribute("name", "q" + stateName);

        if (initialStates.contains(stateName)) {
            Element initial = doc.createElement("initial");
            state.appendChild(initial);
        }

        if (finalStates.contains(stateName)) {
            Element accepting = doc.createElement("final");
            state.appendChild(accepting);
        }

        automaton.appendChild(state);
    }

    for (Triple<String, String, String> transition : this.transitions) {
        Element t = doc.createElement("transition");

        Element from = doc.createElement("from");
        from.setTextContent(transition.getLeft());
        t.appendChild(from);

        Element to = doc.createElement("to");
        to.setTextContent(transition.getMiddle());
        t.appendChild(to);

        Element read = doc.createElement("read");
        read.setTextContent(transition.getRight());
        t.appendChild(read);

        automaton.appendChild(t);
    }

    structure.appendChild(automaton);
    return doc;
}

From source file:storm.lrb.bolt.LastAverageSpeedBolt.java

private void emitLav(Triple<Integer, Integer, Integer> xsd, List<Integer> vehicleCounts,
        List<Double> speedValues, int minute) {

    double speedAverage = this.calcLav(speedValues, minute);
    int segmentCarCount = vehicleCounts.get(minute);

    this.collector.emit(new Values(xsd.getLeft(), xsd.getMiddle(), xsd.getRight(), segmentCarCount,
            speedAverage, minute + 1));//from  w w  w  .  j a  v a2 s .  c  o m
}

From source file:urls.CurlStore.java

public Pair<String, InputStream> get() {
    final Triple<String, Process, Long> triple = QUEUE.poll();
    if (triple == null)
        return null;

    final Process process = triple.getMiddle();
    final Long startTime = triple.getRight();
    final String url = triple.getLeft();

    if (process.isAlive()) {
        if (System.currentTimeMillis() - startTime < timeout)
            QUEUE.offer(triple);//  ww  w. j  a  v a2  s .c om
        else {
            process.destroy();
            EXIT_VALUES.append(". ");
        }
        return null;
    }

    if (process.exitValue() != 0) {
        EXIT_VALUES.append(process.exitValue() + " ");
        return null;
    }

    return Pair.of(url, process.getInputStream());
}