You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by albertostratio <gi...@git.apache.org> on 2014/10/02 11:26:07 UTC
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
GitHub user albertostratio opened a pull request:
https://github.com/apache/incubator-metamodel/pull/2
Cassandra DB support for MetaModel [METAMODEL-18]
Cassandra DB support using the datastax java driver, see: https://github.com/datastax/java-driver
Integration tests have been also added. These tests need a cassandra instance running, properties to enable the integration test for this module have been added to the example-metamodel-integrationtest.configuration.properties file.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/albertostratio/incubator-metamodel master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-metamodel/pull/2.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #2
----
commit 67c877cfde9407e96f4b7fd8805c1ea2d7148f37
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T07:12:53Z
Cassandra module using datastax java driver initial commit.
commit 9930a3e5cd78bb668ee7fa7f1b7a7ad6e52da694
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T07:19:14Z
Native implementation of maxRows method.
commit db4e362542e7e291045f4eff5de179530ef3c87b
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T08:52:40Z
Native implementation for countAll.
commit 2fbaef514c822b495fefa5284e3231e0229db644
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T08:57:20Z
Modify matching for VARINT and LIST metadata types.
commit ec95e15b78d2c1be710e471e3cb080fb5f669802
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T09:15:42Z
Added createCassandraDataContext method to the Factory.
commit b7f31048bdceadf9c48584953dcd604ad36e2ad5
Author: Alberto Rodriguez <al...@paradigmatecnologico.com>
Date: 2014-10-02T09:24:02Z
"Full" excluding of org.codehaus.jackson as we are using integration tests instead of cassandra-unit tests.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18390544
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataSet.java ---
@@ -0,0 +1,83 @@
+/**
+ * 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.metamodel.cassandra;
+
+
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+
+final class CassandraDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory.getLogger(CassandraDataSet.class);
+
+ private final Iterator<com.datastax.driver.core.Row> _cursor;
+ private final boolean _queryPostProcessed;
+
+ private boolean _closed;
+ private volatile com.datastax.driver.core.Row _dbObject;
+
+ public CassandraDataSet(Iterator<com.datastax.driver.core.Row> cursor, Column[] columns, boolean queryPostProcessed) {
+ super(columns);
+ _cursor = cursor;
+ _queryPostProcessed = queryPostProcessed;
+ _closed = false;
+ }
+
+ public boolean isQueryPostProcessed() {
+ return _queryPostProcessed;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ _closed = true;
--- End diff --
At first the DataSet constructor received the ResultSet instead of the Iterator because I thought the ResultSet was closeable, when I find out that is not I decided to pass in the iterator and simply do nothing within the close method.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on the pull request:
https://github.com/apache/incubator-metamodel/pull/2#issuecomment-59169101
Hi Kasper, no worries at all. I worked on the issues that you and Henry opened and they are all fixed/resolved.
IMHO the module is already to be added to MM.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18383366
--- Diff: cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java ---
@@ -0,0 +1,245 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.data.FilteredDataSet;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Table;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CassandraDataContextTest extends CassandraTestCase {
+
+ private CassandraSimpleClient client = new CassandraSimpleClient();
+ private Cluster cluster;
+ private CassandraDataContext dc;
+ private String testTableName = "songs";
+ private String firstRowId = "756716f7-2e54-4715-9f00-91dcbea6cf51";
+ private String secondRowId = "756716f7-2e54-4715-9f00-91dcbea6cf52";
+ private String thirdRowId = "756716f7-2e54-4715-9f00-91dcbea6cf53";
+ private String firstRowTitle = "My first song";
+ private String secondRowTitle = "My second song";
+ private String thirdRowTitle = "My third song";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (isConfigured()) {
+ client.connect(getHostname(), getPort());
+ cluster = client.getCluster();
+ Session session = cluster.connect();
+ dc = new CassandraDataContext(cluster, getKeyspaceName());
+ createCassandraKeySpaceAndTable(session);
+ populateCassandraTableWithSomeData(session);
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (isConfigured()) {
+ client.close();
+ }
+ }
+
+ public void testSchemaAndSimpleQuery() throws Exception {
+ if (!isConfigured()) {
+ System.err.println(getInvalidConfigurationMessage());
+ return;
+ }
+
+ assertEquals("["+testTableName+"]",
+ Arrays.toString(dc.getDefaultSchema().getTableNames()));
+
+ Table table = dc.getDefaultSchema().getTableByName(testTableName);
+
+ assertEquals(ColumnType.STRING, table.getColumnByName("id").getType());
+ assertEquals(ColumnType.STRING, table.getColumnByName("title").getType());
+ assertEquals(ColumnType.BOOLEAN, table.getColumnByName("hit").getType());
+ assertEquals(ColumnType.FLOAT, table.getColumnByName("duration").getType());
+ assertEquals(ColumnType.INTEGER, table.getColumnByName("position").getType());
+ assertEquals(ColumnType.TIMESTAMP, table.getColumnByName("creationtime").getType());
+
+
+ DataSet ds = dc.query().from(testTableName).select("id").and("title").execute();
+ assertEquals(CassandraDataSet.class, ds.getClass());
+ assertFalse(((CassandraDataSet) ds).isQueryPostProcessed());
+
+
+ try {
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+secondRowId+", "+secondRowTitle+"]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+thirdRowId+", "+thirdRowTitle+"]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+firstRowId+", "+firstRowTitle+"]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ } finally {
+ // ds.close();
+ }
+ }
+
+ public void testWhereColumnEqualsValues() throws Exception {
+ DataSet ds = dc.query().from(testTableName).select("id").and("title").where("id")
--- End diff --
Good catch! Fixed!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on the pull request:
https://github.com/apache/incubator-metamodel/pull/2#issuecomment-59168211
Alberto, I'm sorry if I missed this pull request for some time ... What is the status of it in your opinion? Do you want another review, or are you still working on it, or did you mean for it to be added to MM as is?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351318
--- Diff: cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java ---
@@ -0,0 +1,245 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.data.DataSetTableModel;
+import org.apache.metamodel.data.FilteredDataSet;
+import org.apache.metamodel.query.FunctionType;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
+import org.apache.metamodel.schema.ColumnType;
+import org.apache.metamodel.schema.Table;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.table.TableModel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CassandraDataContextTest extends CassandraTestCase {
+
+ private CassandraSimpleClient client = new CassandraSimpleClient();
+ private Cluster cluster;
+ private CassandraDataContext dc;
+ private String testTableName = "songs";
+ private String firstRowId = "756716f7-2e54-4715-9f00-91dcbea6cf51";
+ private String secondRowId = "756716f7-2e54-4715-9f00-91dcbea6cf52";
+ private String thirdRowId = "756716f7-2e54-4715-9f00-91dcbea6cf53";
+ private String firstRowTitle = "My first song";
+ private String secondRowTitle = "My second song";
+ private String thirdRowTitle = "My third song";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (isConfigured()) {
+ client.connect(getHostname(), getPort());
+ cluster = client.getCluster();
+ Session session = cluster.connect();
+ dc = new CassandraDataContext(cluster, getKeyspaceName());
+ createCassandraKeySpaceAndTable(session);
+ populateCassandraTableWithSomeData(session);
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (isConfigured()) {
+ client.close();
+ }
+ }
+
+ public void testSchemaAndSimpleQuery() throws Exception {
+ if (!isConfigured()) {
+ System.err.println(getInvalidConfigurationMessage());
+ return;
+ }
+
+ assertEquals("["+testTableName+"]",
+ Arrays.toString(dc.getDefaultSchema().getTableNames()));
+
+ Table table = dc.getDefaultSchema().getTableByName(testTableName);
+
+ assertEquals(ColumnType.STRING, table.getColumnByName("id").getType());
+ assertEquals(ColumnType.STRING, table.getColumnByName("title").getType());
+ assertEquals(ColumnType.BOOLEAN, table.getColumnByName("hit").getType());
+ assertEquals(ColumnType.FLOAT, table.getColumnByName("duration").getType());
+ assertEquals(ColumnType.INTEGER, table.getColumnByName("position").getType());
+ assertEquals(ColumnType.TIMESTAMP, table.getColumnByName("creationtime").getType());
+
+
+ DataSet ds = dc.query().from(testTableName).select("id").and("title").execute();
+ assertEquals(CassandraDataSet.class, ds.getClass());
+ assertFalse(((CassandraDataSet) ds).isQueryPostProcessed());
+
+
+ try {
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+secondRowId+", "+secondRowTitle+"]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+thirdRowId+", "+thirdRowTitle+"]]", ds.getRow().toString());
+ assertTrue(ds.next());
+ assertEquals("Row[values=["+firstRowId+", "+firstRowTitle+"]]", ds.getRow().toString());
+ assertFalse(ds.next());
+ } finally {
+ // ds.close();
+ }
+ }
+
+ public void testWhereColumnEqualsValues() throws Exception {
+ DataSet ds = dc.query().from(testTableName).select("id").and("title").where("id")
--- End diff --
All test methods should check isConfigured(), or else it will break on a non-configured machine's build
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by hsaputra <gi...@git.apache.org>.
Github user hsaputra commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18398752
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java ---
@@ -0,0 +1,205 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.*;
+import org.apache.metamodel.util.SimpleTableDef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DataContext implementation for Apache Cassandra database.
+ *
+ * When instantiating this DataContext, a keyspace name is provided. In Cassandra,
+ * the keyspace is the container for your application data, similar to a schema in
+ * a relational database. Keyspaces are used to group column families together.
+ *
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
+ *
+ * @author Alberto Rodriguez
--- End diff --
Thx for the info. I thought we removed them but unfortunately still miss some
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on the pull request:
https://github.com/apache/incubator-metamodel/pull/2#issuecomment-57660498
Very good work Alberto! Except for the remarks I've made, I'm very happy with everything I see. If you can attend to those remarks, then I'd certainly give it my +1 :-)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351184
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDBUtils.java ---
@@ -0,0 +1,80 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.ColumnDefinitions;
+import com.datastax.driver.core.DataType;
+import org.apache.metamodel.data.DataSetHeader;
+import org.apache.metamodel.data.DefaultRow;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.query.SelectItem;
+
+/**
+ * A utility class for Cassandra module.
+ *
+ * @author Alberto Rodriguez
+ */
+public class CassandraDBUtils {
+
+ /**
+ * Converts a Cassandra Row data object {@link com.datastax.driver.core.Row}
+ * into MetaModel {@link org.apache.metamodel.data.Row}.
+ *
+ * @param dbObject a Cassandra object storing data.
+ * @param header a header describing the columns of the data stored.
+ * @return the MetaModel {@link org.apache.metamodel.data.Row} result object.
+ */
+ public static Row toRow(com.datastax.driver.core.Row dbObject, DataSetHeader header) {
+
+ if (dbObject == null) {
+ return null;
+ }
+
+ final int size = header.size();
+
+ final Object[] values = new Object[size];
+ for (int i = 0; i < values.length; i++) {
+ final SelectItem selectItem = header.getSelectItem(i);
+ final String key = selectItem.getColumn().getName();
+ values[i] = getColumnValue(key, dbObject);
+ }
+ return new DefaultRow(header, values);
+ }
+
+ private static Object getColumnValue(String columnName, com.datastax.driver.core.Row row) {
+ ColumnDefinitions columns = row.getColumnDefinitions();
+ DataType columnType = columns.getType(columnName);
+ switch (columnType.getName()) {
+ case BIGINT: return row.getVarint(columnName);
+ case BOOLEAN: return row.getBool(columnName);
+ case DECIMAL: return row.getDecimal(columnName);
+ case DOUBLE: return row.getDouble(columnName);
+ case FLOAT: return row.getFloat(columnName);
+ case INET: return row.getInet(columnName);
+ case INT: return row.getInt(columnName);
+ case UUID: return row.getUUID(columnName);
--- End diff --
Here we return a UUID instance, while the ColumnType will be STRING. I suggest we create a UUID ColumnType so that the value corresponds to the expected type. The same principle applies probably to other column types ... Set, Map, Inet and more.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351203
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java ---
@@ -0,0 +1,205 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.*;
+import org.apache.metamodel.util.SimpleTableDef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DataContext implementation for Apache Cassandra database.
+ *
+ * When instantiating this DataContext, a keyspace name is provided. In Cassandra,
+ * the keyspace is the container for your application data, similar to a schema in
+ * a relational database. Keyspaces are used to group column families together.
+ *
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
+ *
+ * @author Alberto Rodriguez
+ */
+public class CassandraDataContext extends QueryPostprocessDataContext implements DataContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(CassandraDataContext.class);
+
+ private final Cluster cassandraCluster;
+ private final SimpleTableDef[] tableDefs;
+ private final String keySpaceName;
+
+ /**
+ * Constructs a {@link CassandraDataContext}. This constructor accepts a
+ * custom array of {@link SimpleTableDef}s which allows the user to define
+ * his own view on the indexes in the engine.
+ *
+ * @param cluster
+ * the Cassandra cluster
+ * @param keySpace
+ * the name of the Cassandra keyspace
+ * @param tableDefs
+ * an array of {@link SimpleTableDef}s, which define the table
+ * and column model of the ElasticSearch index.
+ */
+ public CassandraDataContext(Cluster cluster, String keySpace, SimpleTableDef... tableDefs) {
+ this.cassandraCluster = cluster;
+ this.keySpaceName = keySpace;
+ this.tableDefs = tableDefs;
+ }
+
+ /**
+ * Constructs a {@link CassandraDataContext} and automatically detects
+ * the schema structure/view on the keyspace (see
+ * {@link #detectSchema(Cluster, String)}).
+ *
+ * @param cluster
+ * the Cassandra cluster
+ * @param keySpace
+ * the name of the Cassandra keyspace to represent
+ */
+ public CassandraDataContext(Cluster cluster, String keySpace) {
+ this(cluster, keySpace, detectSchema(cluster, keySpace));
+ }
+
+ /**
+ * Performs an analysis of the given keyspace in a Cassandra cluster
+ * {@link Cluster} instance and detects the cassandra types structure
+ * based on the metadata provided by the datastax cassandra java client.
+ *
+ * @see #detectTable(TableMetadata)
+ *
+ * @param cluster
+ * the cluster to inspect
+ * @param keyspaceName
+ * @return a mutable schema instance, useful for further fine tuning by the
+ * user.
+ */
+ public static SimpleTableDef[] detectSchema(Cluster cluster, String keyspaceName) {
+ Metadata metadata = cluster.getMetadata();
+ KeyspaceMetadata keyspace = metadata.getKeyspace(keyspaceName);
+ Collection<TableMetadata> tables = keyspace.getTables();
+ SimpleTableDef[] result = new SimpleTableDef[tables.size()];
+ int i = 0;
+ for (TableMetadata tableMetaData : tables) {
+ SimpleTableDef table = detectTable(tableMetaData);
+ result[i] = table;
+ i++;
+ }
+ return result;
+ }
+
+ /**
+ * Performs an analysis of an available table in Cassandra.
+ *
+ * @param tableMetaData
+ * the table meta data
+ * @return a table definition for cassandra.
+ */
+ public static SimpleTableDef detectTable(TableMetadata tableMetaData) {
+ List<ColumnMetadata> columns = tableMetaData.getColumns();
+ final String[] columnNames = new String[columns.size()];
+ final ColumnType[] columnTypes = new ColumnType[columns.size()];
+ int i = 0;
+ for (ColumnMetadata column: columns) {
+ columnNames[i] = column.getName();
+ columnTypes[i] = getColumnTypeFromMetaDataField(column.getType().getName());
+ i++;
+ }
+
+ return new SimpleTableDef(tableMetaData.getName(), columnNames, columnTypes);
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ final MutableSchema theSchema = new MutableSchema(getMainSchemaName());
+ for (final SimpleTableDef tableDef : tableDefs) {
+ final MutableTable table = tableDef.toTable().setSchema(theSchema);
+ theSchema.addTable(table);
+ }
+ return theSchema;
+ }
+
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return keySpaceName;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ Select query = QueryBuilder.select().all().from(keySpaceName, table.getName());
+ if (limitMaxRowsIsSet(maxRows)) {
+ query.limit(maxRows);
+ }
+ final Iterator<Row> response = cassandraCluster.connect().execute(query).iterator();
+ return new CassandraDataSet(response, columns, false);
+ }
+
+ private boolean limitMaxRowsIsSet(int maxRows) {
+ return (maxRows != -1);
+ }
+
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ if (!whereItems.isEmpty()) {
+ // not supported - will have to be done by counting client-side
+ return null;
+ }
+ Statement statement = QueryBuilder.select().countAll().from(keySpaceName, table.getName());
+ final Row response = cassandraCluster.connect().execute(statement).one();
+ return response.getLong(0);
+ }
+
+
+ private static ColumnType getColumnTypeFromMetaDataField(DataType.Name metaDataName) {
+ switch (metaDataName) {
+ case BIGINT: return ColumnType.BIGINT;
+ case BLOB: return ColumnType.BLOB;
+ case BOOLEAN: return ColumnType.BOOLEAN;
+ case DECIMAL: return ColumnType.DECIMAL;
+ case DOUBLE: return ColumnType.DOUBLE;
+ case FLOAT: return ColumnType.FLOAT;
+ case INT: return ColumnType.INTEGER;
+ case TEXT: return ColumnType.STRING;
+ case TIMESTAMP: return ColumnType.TIMESTAMP;
+ case UUID: return ColumnType.STRING;
--- End diff --
This line is what I am referring to in the previous comment.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351261
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataSet.java ---
@@ -0,0 +1,83 @@
+/**
+ * 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.metamodel.cassandra;
+
+
+import org.apache.metamodel.data.AbstractDataSet;
+import org.apache.metamodel.data.Row;
+import org.apache.metamodel.schema.Column;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+
+final class CassandraDataSet extends AbstractDataSet {
+
+ private static final Logger logger = LoggerFactory.getLogger(CassandraDataSet.class);
+
+ private final Iterator<com.datastax.driver.core.Row> _cursor;
+ private final boolean _queryPostProcessed;
+
+ private boolean _closed;
+ private volatile com.datastax.driver.core.Row _dbObject;
+
+ public CassandraDataSet(Iterator<com.datastax.driver.core.Row> cursor, Column[] columns, boolean queryPostProcessed) {
+ super(columns);
+ _cursor = cursor;
+ _queryPostProcessed = queryPostProcessed;
+ _closed = false;
+ }
+
+ public boolean isQueryPostProcessed() {
+ return _queryPostProcessed;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ _closed = true;
--- End diff --
I wonder if we need to close something ... Obviously the Iterator is not closeable, but maybe we forgot to carry along the thing that is closeable? That would be quite common when dealing with a streaming resource.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18383484
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java ---
@@ -0,0 +1,205 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.*;
+import org.apache.metamodel.util.SimpleTableDef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DataContext implementation for Apache Cassandra database.
+ *
+ * When instantiating this DataContext, a keyspace name is provided. In Cassandra,
+ * the keyspace is the container for your application data, similar to a schema in
+ * a relational database. Keyspaces are used to group column families together.
+ *
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
+ *
+ * @author Alberto Rodriguez
--- End diff --
I removed the author tags from the classes. Anyway, I included the tag because there are plenty of classes with these tags so I think we should double check this issue.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351406
--- Diff: full/src/main/java/org/apache/metamodel/DataContextFactory.java ---
@@ -649,4 +651,16 @@ public static UpdateableDataContext createCouchDbDataContext(String hostname, In
public static QueryPostprocessDataContext createElasticSearchDataContext(Client client, String indexName) {
return new ElasticSearchDataContext(client, indexName);
}
+
+ /**
+ * Creates a new Cassandra datacontext.
+ * @param cluster
+ * The Cassandra client
+ * @param keySpaceName
+ * The Cassandra key space name
+ * @return a DataContext object that matches the request
+ */
+ public static QueryPostprocessDataContext createCassandraDataContext(Cluster cluster, String keySpaceName) {
--- End diff --
Should return DataContext (the interface) and not QueryPostprocessDataContext (an abstract class which we don't want to expose to end-users).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-metamodel/pull/2
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18383837
--- Diff: cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraSimpleClient.java ---
@@ -0,0 +1,42 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Metadata;
+
+public class CassandraSimpleClient {
--- End diff --
Done!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18390115
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java ---
@@ -0,0 +1,205 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.*;
+import org.apache.metamodel.util.SimpleTableDef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DataContext implementation for Apache Cassandra database.
+ *
+ * When instantiating this DataContext, a keyspace name is provided. In Cassandra,
+ * the keyspace is the container for your application data, similar to a schema in
+ * a relational database. Keyspaces are used to group column families together.
+ *
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
+ *
+ * @author Alberto Rodriguez
+ */
+public class CassandraDataContext extends QueryPostprocessDataContext implements DataContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(CassandraDataContext.class);
+
+ private final Cluster cassandraCluster;
+ private final SimpleTableDef[] tableDefs;
+ private final String keySpaceName;
+
+ /**
+ * Constructs a {@link CassandraDataContext}. This constructor accepts a
+ * custom array of {@link SimpleTableDef}s which allows the user to define
+ * his own view on the indexes in the engine.
+ *
+ * @param cluster
+ * the Cassandra cluster
+ * @param keySpace
+ * the name of the Cassandra keyspace
+ * @param tableDefs
+ * an array of {@link SimpleTableDef}s, which define the table
+ * and column model of the ElasticSearch index.
+ */
+ public CassandraDataContext(Cluster cluster, String keySpace, SimpleTableDef... tableDefs) {
+ this.cassandraCluster = cluster;
+ this.keySpaceName = keySpace;
+ this.tableDefs = tableDefs;
+ }
+
+ /**
+ * Constructs a {@link CassandraDataContext} and automatically detects
+ * the schema structure/view on the keyspace (see
+ * {@link #detectSchema(Cluster, String)}).
+ *
+ * @param cluster
+ * the Cassandra cluster
+ * @param keySpace
+ * the name of the Cassandra keyspace to represent
+ */
+ public CassandraDataContext(Cluster cluster, String keySpace) {
+ this(cluster, keySpace, detectSchema(cluster, keySpace));
+ }
+
+ /**
+ * Performs an analysis of the given keyspace in a Cassandra cluster
+ * {@link Cluster} instance and detects the cassandra types structure
+ * based on the metadata provided by the datastax cassandra java client.
+ *
+ * @see #detectTable(TableMetadata)
+ *
+ * @param cluster
+ * the cluster to inspect
+ * @param keyspaceName
+ * @return a mutable schema instance, useful for further fine tuning by the
+ * user.
+ */
+ public static SimpleTableDef[] detectSchema(Cluster cluster, String keyspaceName) {
+ Metadata metadata = cluster.getMetadata();
+ KeyspaceMetadata keyspace = metadata.getKeyspace(keyspaceName);
+ Collection<TableMetadata> tables = keyspace.getTables();
+ SimpleTableDef[] result = new SimpleTableDef[tables.size()];
+ int i = 0;
+ for (TableMetadata tableMetaData : tables) {
+ SimpleTableDef table = detectTable(tableMetaData);
+ result[i] = table;
+ i++;
+ }
+ return result;
+ }
+
+ /**
+ * Performs an analysis of an available table in Cassandra.
+ *
+ * @param tableMetaData
+ * the table meta data
+ * @return a table definition for cassandra.
+ */
+ public static SimpleTableDef detectTable(TableMetadata tableMetaData) {
+ List<ColumnMetadata> columns = tableMetaData.getColumns();
+ final String[] columnNames = new String[columns.size()];
+ final ColumnType[] columnTypes = new ColumnType[columns.size()];
+ int i = 0;
+ for (ColumnMetadata column: columns) {
+ columnNames[i] = column.getName();
+ columnTypes[i] = getColumnTypeFromMetaDataField(column.getType().getName());
+ i++;
+ }
+
+ return new SimpleTableDef(tableMetaData.getName(), columnNames, columnTypes);
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ final MutableSchema theSchema = new MutableSchema(getMainSchemaName());
+ for (final SimpleTableDef tableDef : tableDefs) {
+ final MutableTable table = tableDef.toTable().setSchema(theSchema);
+ theSchema.addTable(table);
+ }
+ return theSchema;
+ }
+
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return keySpaceName;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ Select query = QueryBuilder.select().all().from(keySpaceName, table.getName());
+ if (limitMaxRowsIsSet(maxRows)) {
+ query.limit(maxRows);
+ }
+ final Iterator<Row> response = cassandraCluster.connect().execute(query).iterator();
+ return new CassandraDataSet(response, columns, false);
+ }
+
+ private boolean limitMaxRowsIsSet(int maxRows) {
+ return (maxRows != -1);
+ }
+
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ if (!whereItems.isEmpty()) {
+ // not supported - will have to be done by counting client-side
+ return null;
+ }
+ Statement statement = QueryBuilder.select().countAll().from(keySpaceName, table.getName());
+ final Row response = cassandraCluster.connect().execute(statement).one();
+ return response.getLong(0);
+ }
+
+
+ private static ColumnType getColumnTypeFromMetaDataField(DataType.Name metaDataName) {
+ switch (metaDataName) {
+ case BIGINT: return ColumnType.BIGINT;
+ case BLOB: return ColumnType.BLOB;
+ case BOOLEAN: return ColumnType.BOOLEAN;
+ case DECIMAL: return ColumnType.DECIMAL;
+ case DOUBLE: return ColumnType.DOUBLE;
+ case FLOAT: return ColumnType.FLOAT;
+ case INT: return ColumnType.INTEGER;
+ case TEXT: return ColumnType.STRING;
+ case TIMESTAMP: return ColumnType.TIMESTAMP;
+ case UUID: return ColumnType.STRING;
--- End diff --
Added new ColumnTypes for Sets, UUID and Inet address
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by albertostratio <gi...@git.apache.org>.
Github user albertostratio commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18383384
--- Diff: full/src/main/java/org/apache/metamodel/DataContextFactory.java ---
@@ -649,4 +651,16 @@ public static UpdateableDataContext createCouchDbDataContext(String hostname, In
public static QueryPostprocessDataContext createElasticSearchDataContext(Client client, String indexName) {
return new ElasticSearchDataContext(client, indexName);
}
+
+ /**
+ * Creates a new Cassandra datacontext.
+ * @param cluster
+ * The Cassandra client
+ * @param keySpaceName
+ * The Cassandra key space name
+ * @return a DataContext object that matches the request
+ */
+ public static QueryPostprocessDataContext createCassandraDataContext(Cluster cluster, String keySpaceName) {
--- End diff --
Another good point. I have also modified the createElasticSearchDataContext that was returning also a QueryPostprocessDataContext
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by hsaputra <gi...@git.apache.org>.
Github user hsaputra commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351813
--- Diff: cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraSimpleClient.java ---
@@ -0,0 +1,42 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Metadata;
+
+public class CassandraSimpleClient {
--- End diff --
Add JavaDoc class header comment why the class is created for.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metamodel pull request: Cassandra DB support for MetaMod...
Posted by hsaputra <gi...@git.apache.org>.
Github user hsaputra commented on a diff in the pull request:
https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351728
--- Diff: cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDataContext.java ---
@@ -0,0 +1,205 @@
+/**
+ * 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.metamodel.cassandra;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+
+import org.apache.metamodel.DataContext;
+import org.apache.metamodel.MetaModelException;
+import org.apache.metamodel.QueryPostprocessDataContext;
+import org.apache.metamodel.data.DataSet;
+import org.apache.metamodel.query.FilterItem;
+import org.apache.metamodel.schema.*;
+import org.apache.metamodel.util.SimpleTableDef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DataContext implementation for Apache Cassandra database.
+ *
+ * When instantiating this DataContext, a keyspace name is provided. In Cassandra,
+ * the keyspace is the container for your application data, similar to a schema in
+ * a relational database. Keyspaces are used to group column families together.
+ *
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
+ *
+ * @author Alberto Rodriguez
--- End diff --
We do not use @author tag in the MetaModel project so need to remove them
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---