Search in sources :

Example 1 with VersionNumber

use of com.datastax.driver.core.VersionNumber in project cassandra by apache.

the class CassandraVersionTest method multipleBuild.

@Test
public void multipleBuild() {
    for (String version : Arrays.asList("4.0+alpha1.SNAPSHOT", "4.0.1+alpha1.SNAPSHOT", "4.0.1.1+alpha1.SNAPSHOT", "4.0.0.0+a.b.c.d.e.f.g")) {
        CassandraVersion cassandra = new CassandraVersion(version);
        VersionNumber client = VersionNumber.parse(version);
        Assert.assertEquals(cassandra.major, client.getMajor());
        Assert.assertEquals(cassandra.minor, client.getMinor());
        Assert.assertEquals(cassandra.patch, client.getPatch());
        Assert.assertEquals(cassandra.hotfix, client.getDSEPatch());
        Assert.assertEquals(cassandra.getBuild(), Splitter.on(".").splitToList(client.getBuildLabel()));
    }
}
Also used : JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) VersionNumber(com.datastax.driver.core.VersionNumber) Test(org.junit.Test)

Example 2 with VersionNumber

use of com.datastax.driver.core.VersionNumber in project cassandra by apache.

the class CassandraVersionTest method multiplePreRelease.

@Test
public void multiplePreRelease() {
    for (String version : Arrays.asList("4.0-alpha1-SNAPSHOT", "4.0.1-alpha1-SNAPSHOT", "4.0.1.1-alpha1-SNAPSHOT", "4.0.0.0-a-b-c-d-e-f-g")) {
        CassandraVersion cassandra = new CassandraVersion(version);
        VersionNumber client = VersionNumber.parse(version);
        Assert.assertEquals(cassandra.major, client.getMajor());
        Assert.assertEquals(cassandra.minor, client.getMinor());
        Assert.assertEquals(cassandra.patch, client.getPatch());
        Assert.assertEquals(cassandra.hotfix, client.getDSEPatch());
        Assert.assertEquals(cassandra.getPreRelease(), client.getPreReleaseLabels());
    }
}
Also used : JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) VersionNumber(com.datastax.driver.core.VersionNumber) Test(org.junit.Test)

Example 3 with VersionNumber

use of com.datastax.driver.core.VersionNumber in project presto by prestodb.

the class CassandraClusteringPredicatesExtractor method getClusteringKeysSet.

private static ClusteringPushDownResult getClusteringKeysSet(List<CassandraColumnHandle> clusteringColumns, TupleDomain<ColumnHandle> predicates, VersionNumber cassandraVersion) {
    ImmutableMap.Builder<ColumnHandle, Domain> domainsBuilder = ImmutableMap.builder();
    ImmutableList.Builder<String> clusteringColumnSql = ImmutableList.builder();
    int currentClusteringColumn = 0;
    for (CassandraColumnHandle columnHandle : clusteringColumns) {
        Domain domain = predicates.getDomains().get().get(columnHandle);
        if (domain == null) {
            break;
        }
        if (domain.isNullAllowed()) {
            break;
        }
        String predicateString = null;
        predicateString = domain.getValues().getValuesProcessor().transform(ranges -> {
            List<Object> singleValues = new ArrayList<>();
            List<String> rangeConjuncts = new ArrayList<>();
            String predicate = null;
            for (Range range : ranges.getOrderedRanges()) {
                if (range.isAll()) {
                    return null;
                }
                if (range.isSingleValue()) {
                    singleValues.add(CassandraCqlUtils.cqlValue(toCQLCompatibleString(range.getSingleValue()), columnHandle.getCassandraType()));
                } else {
                    if (!range.isLowUnbounded()) {
                        rangeConjuncts.add(format("%s %s %s", CassandraCqlUtils.validColumnName(columnHandle.getName()), range.isLowInclusive() ? ">=" : ">", CassandraCqlUtils.cqlValue(toCQLCompatibleString(range.getLowBoundedValue()), columnHandle.getCassandraType())));
                    }
                    if (!range.isHighUnbounded()) {
                        rangeConjuncts.add(format("%s %s %s", CassandraCqlUtils.validColumnName(columnHandle.getName()), range.isHighInclusive() ? "<=" : "<", CassandraCqlUtils.cqlValue(toCQLCompatibleString(range.getHighBoundedValue()), columnHandle.getCassandraType())));
                    }
                }
            }
            if (!singleValues.isEmpty() && !rangeConjuncts.isEmpty()) {
                return null;
            }
            if (!singleValues.isEmpty()) {
                if (singleValues.size() == 1) {
                    predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " = " + singleValues.get(0);
                } else {
                    predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " IN (" + Joiner.on(",").join(singleValues) + ")";
                }
            } else if (!rangeConjuncts.isEmpty()) {
                predicate = Joiner.on(" AND ").join(rangeConjuncts);
            }
            return predicate;
        }, discreteValues -> {
            if (discreteValues.isWhiteList()) {
                ImmutableList.Builder<Object> discreteValuesList = ImmutableList.builder();
                for (Object discreteValue : discreteValues.getValues()) {
                    discreteValuesList.add(CassandraCqlUtils.cqlValue(toCQLCompatibleString(discreteValue), columnHandle.getCassandraType()));
                }
                String predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " IN (" + Joiner.on(",").join(discreteValuesList.build()) + ")";
                return predicate;
            }
            return null;
        }, allOrNone -> null);
        if (predicateString == null) {
            break;
        }
        // IN restriction only on last clustering column for Cassandra version = 2.1
        if (predicateString.contains(" IN (") && cassandraVersion.compareTo(VersionNumber.parse("2.2.0")) < 0 && currentClusteringColumn != (clusteringColumns.size() - 1)) {
            break;
        }
        clusteringColumnSql.add(predicateString);
        domainsBuilder.put(columnHandle, domain);
        // Check for last clustering column should only be restricted by range condition
        if (predicateString.contains(">") || predicateString.contains("<")) {
            break;
        }
        currentClusteringColumn++;
    }
    List<String> clusteringColumnPredicates = clusteringColumnSql.build();
    return new ClusteringPushDownResult(domainsBuilder.build(), Joiner.on(" AND ").join(clusteringColumnPredicates));
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) CassandraCqlUtils.toCQLCompatibleString(com.facebook.presto.cassandra.util.CassandraCqlUtils.toCQLCompatibleString) HashMap(java.util.HashMap) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) Range(com.facebook.presto.common.predicate.Range) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) CassandraCqlUtils(com.facebook.presto.cassandra.util.CassandraCqlUtils) VersionNumber(com.datastax.driver.core.VersionNumber) Joiner(com.google.common.base.Joiner) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) CassandraCqlUtils.toCQLCompatibleString(com.facebook.presto.cassandra.util.CassandraCqlUtils.toCQLCompatibleString) Range(com.facebook.presto.common.predicate.Range) ImmutableMap(com.google.common.collect.ImmutableMap) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain)

Aggregations

VersionNumber (com.datastax.driver.core.VersionNumber)3 Test (org.junit.Test)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 CassandraCqlUtils (com.facebook.presto.cassandra.util.CassandraCqlUtils)1 CassandraCqlUtils.toCQLCompatibleString (com.facebook.presto.cassandra.util.CassandraCqlUtils.toCQLCompatibleString)1 Domain (com.facebook.presto.common.predicate.Domain)1 Range (com.facebook.presto.common.predicate.Range)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1