com.facebook.presto.cassandra.CassandraClusteringPredicatesExtractor Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.cassandra;
import com.datastax.driver.core.VersionNumber;
import com.facebook.presto.cassandra.util.CassandraCqlUtils;
import com.facebook.presto.common.predicate.Domain;
import com.facebook.presto.common.predicate.Range;
import com.facebook.presto.common.predicate.TupleDomain;
import com.facebook.presto.spi.ColumnHandle;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.facebook.presto.cassandra.util.CassandraCqlUtils.toCQLCompatibleString;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
public class CassandraClusteringPredicatesExtractor
{
private final List clusteringColumns;
private final ClusteringPushDownResult clusteringPushDownResult;
private final TupleDomain predicates;
public CassandraClusteringPredicatesExtractor(List clusteringColumns, TupleDomain predicates, VersionNumber cassandraVersion)
{
this.clusteringColumns = ImmutableList.copyOf(clusteringColumns);
this.predicates = requireNonNull(predicates, "predicates is null");
this.clusteringPushDownResult = getClusteringKeysSet(clusteringColumns, predicates, requireNonNull(cassandraVersion, "cassandraVersion is null"));
}
public String getClusteringKeyPredicates()
{
return clusteringPushDownResult.getDomainQuery();
}
public TupleDomain getUnenforcedConstraints()
{
Map pushedDown = clusteringPushDownResult.getDomains();
Map notPushedDown = new HashMap<>(predicates.getDomains().get());
if (!notPushedDown.isEmpty() && !pushedDown.isEmpty()) {
notPushedDown.entrySet().removeAll(pushedDown.entrySet());
}
return TupleDomain.withColumnDomains(notPushedDown);
}
private static ClusteringPushDownResult getClusteringKeysSet(List clusteringColumns, TupleDomain predicates, VersionNumber cassandraVersion)
{
ImmutableMap.Builder domainsBuilder = ImmutableMap.builder();
ImmutableList.Builder 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy