Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GORA-650 Add ArangoDB datastore #291

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions gora-arangodb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?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.gora</groupId>
<artifactId>gora</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>gora-arangodb</artifactId>
<packaging>bundle</packaging>

<name>Apache Gora :: ArangoDB</name>
<url>http://gora.apache.org</url>
<description>The Apache Gora open source framework provides an in-memory data model and
persistence for big data. Gora supports persisting to column stores, key value stores,
document stores and RDBMSs, and analyzing the data with extensive Apache Hadoop MapReduce
support.</description>
<inceptionYear>2010</inceptionYear>
<organization>
<name>The Apache Software Foundation</name>
<url>http://www.apache.org/</url>
</organization>
<issueManagement>
<system>JIRA</system>
<url>https://issues.apache.org/jira/browse/GORA</url>
</issueManagement>
<ciManagement>
<system>Jenkins</system>
<url>https://builds.apache.org/job/Gora-trunk/</url>
</ciManagement>

<properties>
<osgi.import>*</osgi.import>
<osgi.export>org.apache.gora.arangodb*;version="${project.version}";-noimport:=true</osgi.export>
</properties>

<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
<!--targetPath>${project.basedir}/target/classes/</targetPath -->
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/examples/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Gora Internal Dependencies -->
<dependency>
<groupId>org.apache.gora</groupId>
<artifactId>gora-core</artifactId>
</dependency>

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

<!-- Logging Dependencies -->

<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<!-- XML Dependencies -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<scope>compile</scope>
</dependency>


<!-- ArangoDB Dependencies -->
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
</dependency>

<!-- Hadoop Dependencies -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.gora.arangodb;
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* 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.gora.arangodb.query;

import org.apache.gora.arangodb.store.ArangoDBMapping;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.impl.QueryBase;
import org.apache.gora.store.DataStore;

import java.util.HashMap;
import java.util.Map;

/**
* ArangoDB specific implementation of the {@link org.apache.gora.query.Query} interface.
*/
public class ArangoDBQuery<K, T extends PersistentBase> extends QueryBase<K, T> {

private String arangoDBQuery;
private Map<String, Object> params;

public ArangoDBQuery() {
super(null);
}

public ArangoDBQuery(DataStore<K, T> dataStore) {
super(dataStore);
}

public String populateArangoDBQuery(final ArangoDBMapping arangoDBMapping,
final boolean isSelect) {
params = new HashMap<String, Object>();
StringBuffer dbQuery = new StringBuffer();
if ((this.getStartKey() != null) && (this.getEndKey() != null)
&& this.getStartKey().equals(this.getEndKey())) {
dbQuery.append("FOR t IN @collection FILTER t._key == @key "
.replace("@collection", arangoDBMapping.getDocumentClass()));
params.put("key", encodeArangoDBKey(this.getStartKey()));
} else if (this.getStartKey() != null && this.getEndKey() != null) {
dbQuery.append("FOR t IN @collection FILTER t._key >= @lower && t._key <= @upper "
.replace("@collection", arangoDBMapping.getDocumentClass()));
params.put("lower", encodeArangoDBKey(this.getStartKey()));
params.put("upper", encodeArangoDBKey(this.getEndKey()));
} else if (this.getStartKey() != null) {
dbQuery.append("FOR t IN @collection FILTER t._key >= @lower "
.replace("@collection", arangoDBMapping.getDocumentClass()));
params.put("lower", encodeArangoDBKey((this.getStartKey())));
} else if (this.getEndKey() != null) {
dbQuery.append("FOR t IN @collection FILTER t._key <= @upper "
.replace("@collection", arangoDBMapping.getDocumentClass()));
params.put("upper", encodeArangoDBKey(this.getEndKey()));
} else {
dbQuery.append("FOR t IN @collection "
.replace("@collection", arangoDBMapping.getDocumentClass()));
}

if (this.getLimit() != -1) {
dbQuery.append("Limit @count ");
params.put("count", this.getLimit());
}

if (isSelect) {
dbQuery.append("RETURN t");
} else {
dbQuery.append("REMOVE t IN @collection".replace("@collection", arangoDBMapping.getDocumentClass()));
}

arangoDBQuery = dbQuery.toString();
return arangoDBQuery;
}

public Map<String, Object> getParams() {
return params;
}

public String getArangoDBQuery() {
return arangoDBQuery;
}

public K encodeArangoDBKey(final K key) {
if (key == null) {
return null;
} else if (!(key instanceof String)) {
return key;
}
return (K) key.toString().replace("/", "%2F")
.replace("&", "%26");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* 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.gora.arangodb.query;

import java.io.IOException;

import com.arangodb.ArangoCursor;
import com.arangodb.ArangoIterator;
import com.arangodb.entity.BaseDocument;
import org.apache.gora.arangodb.store.ArangoDBStore;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.Query;
import org.apache.gora.query.impl.ResultBase;
import org.apache.gora.store.DataStore;

/**
* ArangoDB specific implementation of the {@link org.apache.gora.query.Result} interface.
*
*/
public class ArangoDBResult<K, T extends PersistentBase> extends ResultBase<K, T> {

private int size;
private ArangoCursor<BaseDocument> cursor;
private ArangoIterator<BaseDocument> resultSetIterator;

public ArangoDBResult(DataStore<K, T> dataStore,
Query<K, T> query,
ArangoCursor<BaseDocument> cursor) {
super(dataStore, query);
this.cursor = cursor;
this.resultSetIterator = cursor.iterator();
this.size = cursor.getStats().getFullCount().intValue();
}

public ArangoDBResult(DataStore<K, T> dataStore, Query<K, T> query) {
super(dataStore, query);
}

public ArangoDBStore<K, T> getDataStore() {
return (ArangoDBStore<K, T>) super.getDataStore();
}

@Override
public float getProgress() throws IOException {
if (cursor == null) {
return 0;
} else if (size == 0) {
return 1;
} else {
return offset / (float) size;
}
}

@Override
public void close() throws IOException {
cursor.close();
}

@Override
protected boolean nextInner() throws IOException {
if (!resultSetIterator.hasNext()) {
return false;
}

BaseDocument obj = resultSetIterator.next();
key = (K) obj.getKey();
persistent = ((ArangoDBStore<K, T>) getDataStore())
.convertArangoDBDocToAvroBean(obj, getQuery().getFields());
return persistent != null;
}

@Override
public int size() {
int totalSize = size;
int intLimit = (int) this.limit;
return intLimit > 0 && totalSize > intLimit ? intLimit : totalSize;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.gora.arangodb.query;
Loading
Loading