Skip to content

Commit

Permalink
[CALCITE-2059] Apache Geode Adapter (Christian Tzolov)
Browse files Browse the repository at this point in the history
- Downgrade Geode from 1.4.0 to 1.3.0 - Geode server allows connections
  only from clients with same or lower version
- Add links to presentations and tutorials

Close apache#581
  • Loading branch information
tzolov authored and julianhyde committed Feb 16, 2018
1 parent 3c67a60 commit 707f4de
Show file tree
Hide file tree
Showing 43 changed files with 4,456 additions and 2 deletions.
2 changes: 2 additions & 0 deletions geode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
##Apache Geode SQL/JBC Adapter

189 changes: 189 additions & 0 deletions geode/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.16.0-SNAPSHOT</version>
</parent>

<artifactId>calcite-geode</artifactId>
<packaging>jar</packaging>
<version>1.16.0-SNAPSHOT</version>
<name>Calcite Geode</name>
<description>Geode adapter for Calcite</description>

<properties>
<top.dir>${project.basedir}/..</top.dir>
</properties>

<dependencies>
<!-- Sorted by groupId, artifactId; calcite dependencies first. Put versions
in dependencyManagement in the root POM, not here. -->
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-linq4j</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2</version>
</dependency>

<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>uberjdbc</id>
<dependencies>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<!-- Sorted by groupId, artifactId. Put versions in pluginManagement in
the root POM, not here. -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<!-- ignore "unused but declared" warnings -->
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>org.slf4j:slf4j-api</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.slf4j:slf4j-log4j12</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<!-- Parent module has the same plugin and does the work of generating
-sources.jar for each project. But without the plugin declared here, IDEs
don't know the sources are available. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you 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 org.apache.calcite.adapter.geode.rel;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptCost;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Aggregate;
import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;

import java.util.ArrayList;
import java.util.List;

/**
* Implementation of
* {@link org.apache.calcite.rel.core.Aggregate} relational expression
* in Geode.
*/
public class GeodeAggregate extends Aggregate implements GeodeRel {

/** Creates a GeodeAggregate. */
public GeodeAggregate(RelOptCluster cluster,
RelTraitSet traitSet,
RelNode input,
boolean indicator,
ImmutableBitSet groupSet,
List<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls) {
super(cluster, traitSet, input, indicator, groupSet, groupSets, aggCalls);

assert getConvention() == GeodeRel.CONVENTION;
assert getConvention() == this.input.getConvention();
assert getConvention() == input.getConvention();
assert this.groupSets.size() == 1 : "Grouping sets not supported";

for (AggregateCall aggCall : aggCalls) {
if (aggCall.isDistinct()) {
System.out.println("DISTINCT based aggregation!");
}
}
}

@Override public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator,
ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets,
List<AggregateCall> aggCalls) {
return new GeodeAggregate(getCluster(), traitSet, input, indicator, groupSet, groupSets,
aggCalls);
}

@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
return super.computeSelfCost(planner, mq).multiplyBy(0.1);
}

@Override public void implement(GeodeImplementContext geodeImplementContext) {

((GeodeRel) getInput()).implement(geodeImplementContext);

List<String> inputFields = fieldNames(getInput().getRowType());

List<String> groupByFields = new ArrayList<>();

// GROUP BY field == cardinality of 1, GROUP BY field1, field2 => cardinality of 2 ...
if (groupSet.cardinality() == 1) {
final String groupByFieldName = inputFields.get(groupSet.nth(0));
groupByFields.add(groupByFieldName);
} else {
for (int group : groupSet) {
groupByFields.add(inputFields.get(group));
}
}

geodeImplementContext.addGroupBy(groupByFields);

// Find the aggregate functions (e.g. MAX, SUM ...)
Builder<String, String> aggregateFunctionMap = ImmutableMap.builder();
for (AggregateCall aggCall : aggCalls) {

ArrayList<Object> aggCallFieldNames = new ArrayList<>();
for (int i : aggCall.getArgList()) {
aggCallFieldNames.add(inputFields.get(i));
}
String functionName = aggCall.getAggregation().getName();

// Workaround to handle count(*) case. Geode doesn't allow "AS" aliases on
// 'count(*)' but allows it for count('any column name'). So we are
// converting the count(*) into count (first input ColumnName).
if ("COUNT".equalsIgnoreCase(functionName) && aggCallFieldNames.isEmpty()) {
aggCallFieldNames.add(inputFields.get(0));
}

String oqlAggregateCall = Util.toString(aggCallFieldNames, " " + functionName + "(", ", ",
")");

aggregateFunctionMap.put(aggCall.getName(), oqlAggregateCall);
}

geodeImplementContext.addAggregateFunctions(aggregateFunctionMap.build());

}

private List<String> fieldNames(RelDataType relDataType) {
ArrayList<String> names = new ArrayList<>();

for (RelDataTypeField rdtf : relDataType.getFieldList()) {
names.add(rdtf.getName());
}
return names;
}
}

// End GeodeAggregate.java
Loading

0 comments on commit 707f4de

Please sign in to comment.