Skip to content

Commit

Permalink
TEIID-4213 adding cassandra aggregate pushdown
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Feb 5, 2017
1 parent b694eaf commit e1334b3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
Expand Up @@ -23,6 +23,7 @@
package org.teiid.resource.adapter.cassandra;

import java.util.List;
import java.util.Set;

import javax.resource.ResourceException;

Expand All @@ -41,7 +42,7 @@ public class CassandraConnectionImpl extends BasicConnection implements Cassandr
private Cluster cluster = null;
private Session session = null;
private Metadata metadata = null;
private ProtocolVersion version;
private VersionNumber version;

public CassandraConnectionImpl(CassandraManagedConnectionFactory config, Metadata metadata) {
this.config = config;
Expand All @@ -67,7 +68,11 @@ public CassandraConnectionImpl(CassandraManagedConnectionFactory config) {

this.session = cluster.connect(config.getKeyspace());

this.version = this.session.getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
Set<Host> allHosts = cluster.getMetadata().getAllHosts();
if (!allHosts.isEmpty()) {
Host host = allHosts.iterator().next();
this.version = host.getCassandraVersion();
}
}

@Override
Expand Down Expand Up @@ -125,7 +130,7 @@ public KeyspaceMetadata keyspaceInfo() throws ResourceException {
}

@Override
public ProtocolVersion getVersion() {
public VersionNumber getVersion() {
return version;
}

Expand Down
2 changes: 1 addition & 1 deletion connectors/cassandra/translator-cassandra/pom.xml
Expand Up @@ -136,7 +136,7 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
Expand Down
Expand Up @@ -28,8 +28,8 @@
import javax.resource.cci.Connection;

import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.VersionNumber;

/**
* Connection to Cassandra NoSql database.
Expand Down Expand Up @@ -64,9 +64,9 @@ public interface CassandraConnection extends Connection{
ResultSetFuture executeBatch(String update, List<Object[]> values);

/**
* Get the protocol version in use for this connection
* Get the version in use for this connection
* @return
*/
ProtocolVersion getVersion();
VersionNumber getVersion();

}
Expand Up @@ -44,18 +44,21 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.UpdateExecution;

import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.VersionNumber;


@Translator(name = "cassandra", description = "A translator for Cassandra NoSql database")
public class CassandraExecutionFactory extends ExecutionFactory<ConnectionFactory, CassandraConnection> {
public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CassandraExecutionFactory.class);
private static final VersionNumber DEFAULT_VERSION = VersionNumber.parse("1.2.0"); //$NON-NLS-1$
private static final VersionNumber V2 = VersionNumber.parse("2.0.0"); //$NON-NLS-1$
private static final VersionNumber V2_2 = VersionNumber.parse("2.2.0"); //$NON-NLS-1$
public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CassandraExecutionFactory.class);

public static enum Event implements BundleUtil.Event {
TEIID22000
}

private boolean isV2;
private VersionNumber version;

@Override
public void start() throws TranslatorException {
Expand Down Expand Up @@ -136,34 +139,34 @@ public boolean supportsRowLimit() {

@Override
public boolean supportsBulkUpdate() {
return isV2;
return version.compareTo(V2) >= 0;
}

@Override
public boolean supportsBatchedUpdates() {
return isV2;
}
/*
@Override
public boolean supportsAggregatesSum() {
return true;
}
@Override
public boolean supportsAggregatesAvg() {
return true;
}
@Override
public boolean supportsAggregatesMin() {
return true;
}
@Override
public boolean supportsAggregatesMax() {
return true;
}
*/
return version.compareTo(V2) >= 0;
}

@Override
public boolean supportsAggregatesSum() {
return version.compareTo(V2_2) >= 0;
}

@Override
public boolean supportsAggregatesAvg() {
return version.compareTo(V2_2) >= 0;
}

@Override
public boolean supportsAggregatesMin() {
return version.compareTo(V2_2) >= 0;
}

@Override
public boolean supportsAggregatesMax() {
return version.compareTo(V2_2) >= 0;
}

@Override
public boolean returnsSingleUpdateCount() {
return true;
Expand All @@ -175,8 +178,9 @@ public void initCapabilities(CassandraConnection connection)
if (connection == null) {
return;
}
if (connection.getVersion().compareTo(ProtocolVersion.V2) >= 0) {
this.isV2 = true;
this.version = connection.getVersion();
if (this.version == null) {
this.version = DEFAULT_VERSION;
}
}

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -76,7 +76,7 @@
<mysql.connector.version>5.1.5</mysql.connector.version>
<version.org.codehaus.groovy>2.4.4</version.org.codehaus.groovy>
<version.com.h2database>1.3.152</version.com.h2database>
<version.com.codahale.metrics.metrics-core>3.0.2</version.com.codahale.metrics.metrics-core>
<version.io.dropwizard.metrics.metrics-core>3.1.2</version.io.dropwizard.metrics.metrics-core>
<version.de.flapdoodle.embed.mongo>1.46.0</version.de.flapdoodle.embed.mongo>
<version.org.eclipse.persistence>2.5.0</version.org.eclipse.persistence>
<version.org.apache.olingo>4.3.0</version.org.apache.olingo>
Expand Down Expand Up @@ -1267,9 +1267,9 @@
<version>${version.cassandra-driver-core}</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>${version.com.codahale.metrics.metrics-core}</version>
<version>${version.io.dropwizard.metrics.metrics-core}</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down

0 comments on commit e1334b3

Please sign in to comment.