Search in sources :

Example 21 with Joiner

use of com.google.common.base.Joiner in project YCSB by brianfrankcooper.

the class CloudSpannerClient method readUsingQuery.

private Status readUsingQuery(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    Statement query;
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    if (fields == null || fields.size() == fieldCount) {
        query = Statement.newBuilder(standardQuery).bind("key").to(key).build();
    } else {
        Joiner joiner = Joiner.on(',');
        query = Statement.newBuilder("SELECT ").append(joiner.join(fields)).append(" FROM ").append(table).append(" WHERE id=@key").bind("key").to(key).build();
    }
    try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
        resultSet.next();
        decodeStruct(columns, resultSet, result);
        if (resultSet.next()) {
            throw new Exception("Expected exactly one row for each read.");
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "readUsingQuery()", e);
        return Status.ERROR;
    }
}
Also used : Joiner(com.google.common.base.Joiner) Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.cloud.spanner.ResultSet) DBException(com.yahoo.ycsb.DBException)

Example 22 with Joiner

use of com.google.common.base.Joiner in project YCSB by brianfrankcooper.

the class CloudSpannerClient method scanUsingQuery.

private Status scanUsingQuery(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    Statement query;
    if (fields == null || fields.size() == fieldCount) {
        query = Statement.newBuilder(standardScan).bind("startKey").to(startKey).bind("count").to(recordCount).build();
    } else {
        Joiner joiner = Joiner.on(',');
        query = Statement.newBuilder("SELECT ").append(joiner.join(fields)).append(" FROM ").append(table).append(" WHERE id>=@startKey LIMIT @count").bind("startKey").to(startKey).bind("count").to(recordCount).build();
    }
    try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
        while (resultSet.next()) {
            HashMap<String, ByteIterator> row = new HashMap<>();
            decodeStruct(columns, resultSet, row);
            result.add(row);
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "scanUsingQuery()", e);
        return Status.ERROR;
    }
}
Also used : Joiner(com.google.common.base.Joiner) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.cloud.spanner.ResultSet) DBException(com.yahoo.ycsb.DBException)

Example 23 with Joiner

use of com.google.common.base.Joiner in project crate by crate.

the class TreeAssertions method assertListEquals.

private static <T> void assertListEquals(List<T> actual, List<T> expected) {
    if (actual.size() != expected.size()) {
        Joiner joiner = Joiner.on("\n    ");
        fail(format("Lists not equal%nActual [%s]:%n    %s%nExpected [%s]:%n    %s", actual.size(), joiner.join(actual), expected.size(), joiner.join(expected)));
    }
    assertEquals(actual, expected);
}
Also used : Joiner(com.google.common.base.Joiner)

Example 24 with Joiner

use of com.google.common.base.Joiner in project crate by crate.

the class PingTask method buildPingUrl.

private URL buildPingUrl() throws URISyntaxException, IOException, NoSuchAlgorithmException {
    URI uri = new URI(this.pingUrl);
    Map<String, String> queryMap = new HashMap<>();
    // block until clusterId is available
    queryMap.put("cluster_id", getClusterId());
    queryMap.put("kernel", XContentFactory.jsonBuilder().map(getKernelData()).string());
    queryMap.put("master", isMasterNode().toString());
    queryMap.put("enterprise", isEnterprise());
    queryMap.put("ping_count", XContentFactory.jsonBuilder().map(getCounters()).string());
    queryMap.put("hardware_address", getHardwareAddress());
    queryMap.put("crate_version", getCrateVersion());
    queryMap.put("java_version", getJavaVersion());
    if (logger.isDebugEnabled()) {
        logger.debug("Sending data: {}", queryMap);
    }
    final Joiner joiner = Joiner.on('=');
    List<String> params = new ArrayList<>(queryMap.size());
    for (Map.Entry<String, String> entry : queryMap.entrySet()) {
        if (entry.getValue() != null) {
            params.add(joiner.join(entry.getKey(), entry.getValue()));
        }
    }
    String query = Joiner.on('&').join(params);
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()).toURL();
}
Also used : Joiner(com.google.common.base.Joiner) URI(java.net.URI)

Example 25 with Joiner

use of com.google.common.base.Joiner in project gradle by gradle.

the class DefaultLibraryResolutionErrorMessageBuilder method noCompatibleVariantErrorMessage.

@Override
public String noCompatibleVariantErrorMessage(String libraryName, Iterable<? extends Binary> allBinaries) {
    HashMultimap<String, String> variantAxisMessages = HashMultimap.create();
    for (Binary binary : allBinaries) {
        BinarySpec spec = (BinarySpec) binary;
        VariantsMetaData md = DefaultVariantsMetaData.extractFrom(spec, schemaStore.getSchema(((BinarySpecInternal) spec).getPublicType()));
        Set<String> variantAxesWithIncompatibleTypes = VariantsMetaDataHelper.determineAxesWithIncompatibleTypes(variantsMetaData, md, variantAxesToResolve);
        for (String variantAxis : variantAxesToResolve) {
            String value = md.getValueAsString(variantAxis);
            if (value != null) {
                String message = String.format("'%s'", value);
                if (variantAxesWithIncompatibleTypes.contains(variantAxis)) {
                    message = String.format("%s but with an incompatible type (expected '%s' was '%s')", message, variantsMetaData.getVariantAxisType(variantAxis).getConcreteClass().getName(), md.getVariantAxisType(variantAxis).getConcreteClass().getName());
                }
                variantAxisMessages.put(variantAxis, message);
            }
        }
    }
    Joiner joiner = Joiner.on(", ").skipNulls();
    StringBuilder error = new StringBuilder(String.format(TextUtil.toPlatformLineSeparators("Cannot find a compatible variant for library '%s'.\n"), libraryName));
    for (String variantAxis : variantAxesToResolve) {
        String axisName = renderAxisName(variantAxis);
        error.append("    Required ").append(axisName).append(" '").append(variantsMetaData.getValueAsString(variantAxis)).append("'");
        Set<String> available = new TreeSet<String>(variantAxisMessages.get(variantAxis));
        if (!available.isEmpty()) {
            error.append(", available: ").append(joiner.join(available)).append("\n");
        } else {
            error.append(" but no compatible variant was found\n");
        }
    }
    return error.toString();
}
Also used : Joiner(com.google.common.base.Joiner) BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) TreeSet(java.util.TreeSet) Binary(org.gradle.platform.base.Binary) BinarySpec(org.gradle.platform.base.BinarySpec)

Aggregations

Joiner (com.google.common.base.Joiner)39 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 BufferedWriter (java.io.BufferedWriter)3 List (java.util.List)3 ResultSet (com.google.cloud.spanner.ResultSet)2 Statement (com.google.cloud.spanner.Statement)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 DBException (com.yahoo.ycsb.DBException)2 File (java.io.File)2 URI (java.net.URI)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FileLineDifferenceIterator (org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 PropertyFieldSetter (co.cask.cdap.common.lang.PropertyFieldSetter)1 DataSetFieldSetter (co.cask.cdap.internal.app.runtime.DataSetFieldSetter)1