You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2014/09/24 09:47:23 UTC

[1/3] git commit: METAMODEL-77: Applied patch to use a single index

Repository: incubator-metamodel
Updated Branches:
  refs/heads/master 02e6d4fb8 -> 6aeb35073


METAMODEL-77: Applied patch to use a single index

Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/72bfb77a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/72bfb77a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/72bfb77a

Branch: refs/heads/master
Commit: 72bfb77a968e99b173feb6a079505c73b9fb2e72
Parents: 02e6d4f
Author: Kasper Sørensen <i....@gmail.com>
Authored: Wed Sep 24 09:40:41 2014 +0200
Committer: Kasper Sørensen <i....@gmail.com>
Committed: Wed Sep 24 09:40:41 2014 +0200

----------------------------------------------------------------------
 .../elasticsearch/ElasticSearchDataContext.java | 231 ++++++-------------
 .../ElasticSearchDataContextTest.java           |  96 ++++----
 2 files changed, 120 insertions(+), 207 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/72bfb77a/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java b/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
index 59c379a..c38c0fa 100644
--- a/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
+++ b/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
@@ -18,14 +18,24 @@
  */
 package org.apache.metamodel.elasticsearch;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 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.schema.Column;
+import org.apache.metamodel.schema.MutableSchema;
+import org.apache.metamodel.schema.MutableTable;
+import org.apache.metamodel.schema.Schema;
+import org.apache.metamodel.schema.Table;
 import org.apache.metamodel.util.SimpleTableDef;
-import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
 import org.elasticsearch.action.count.CountResponse;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -40,36 +50,32 @@ import org.elasticsearch.index.query.QueryBuilders;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.*;
-
 /**
  * DataContext implementation for ElasticSearch analytics engine.
  * 
- * ElasticSearch has a data storage structure hierarchy that briefly goes like this:
+ * ElasticSearch has a data storage structure hierarchy that briefly goes like
+ * this:
  * <ul>
  * <li>Index</li>
  * <li>Document type (short: Type) (within an index)</li>
  * <li>Documents (of a particular type)</li>
  * </ul>
  * 
- * TODO: Describe how this is mapped to a schema/table model in MetaModel.
- *
- * Since ElasticSearch has indexes and types a virtual schema will be used in
- * this DataContext where the tables will be the types. We will also maintain a
- * hashmap that will contain the index/type relationship. This implementation
- * supports either automatic discovery of a schema or manual specification of a
- * schema, through the {@link SimpleTableDef} class.
- *
- * @author Alberto Rodriguez
+ * When instantiating this DataContext, an index name is provided. Within this
+ * index, each document type is represented as a table.
+ * 
+ * This implementation supports either automatic discovery of a schema or manual
+ * specification of a schema, through the {@link SimpleTableDef} class.
  */
 public class ElasticSearchDataContext extends QueryPostprocessDataContext implements DataContext {
 
     private static final Logger logger = LoggerFactory.getLogger(ElasticSearchDataContext.class);
+
     private static final String ES_CLUSTER_NAME = "cluster.name";
 
     private final Client elasticSearchClient;
     private final SimpleTableDef[] tableDefs;
-    private HashMap<String, String> typeAndIndexes = new HashMap<String, String>();
+    private final String indexName;
 
     /**
      * Constructs a {@link ElasticSearchDataContext}. This constructor accepts a
@@ -78,12 +84,15 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
      *
      * @param client
      *            the ElasticSearch client
+     * @param indexName
+     *            the name of the ElasticSearch index to represent
      * @param tableDefs
      *            an array of {@link SimpleTableDef}s, which define the table
-     *            and column model of the elasticsearch indexes.
+     *            and column model of the ElasticSearch index.
      */
-    public ElasticSearchDataContext(Client client, SimpleTableDef... tableDefs) {
+    public ElasticSearchDataContext(Client client, String indexName, SimpleTableDef... tableDefs) {
         this.elasticSearchClient = client;
+        this.indexName = indexName;
         this.tableDefs = tableDefs;
     }
 
@@ -94,9 +103,11 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
      *
      * @param client
      *            the ElasticSearch client
+     * @param indexName
+     *            the name of the ElasticSearch index to represent
      */
-    public ElasticSearchDataContext(Client client) {
-        this(client, detectSchema(client));
+    public ElasticSearchDataContext(Client client, String indexName) {
+        this(client, indexName, detectSchema(client, indexName));
     }
 
     /**
@@ -108,37 +119,35 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
      *
      * @param client
      *            the client to inspect
+     * @param indexName2
      * @return a mutable schema instance, useful for further fine tuning by the
      *         user.
      */
-    public static SimpleTableDef[] detectSchema(Client client) {
-        final List<String> indexNames = new ArrayList<String>();
-        final ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().execute().actionGet();
-        final ImmutableOpenMap<String, IndexMetaData> indexes = clusterStateResponse.getState().getMetaData()
-                .getIndices();
-        
-        for (ObjectCursor<String> typeCursor : indexes.keys()) {
-            indexNames.add(typeCursor.value);
-        }
+    public static SimpleTableDef[] detectSchema(Client client, String indexName) {
+        final ClusterState cs = client.admin().cluster().prepareState().setIndices(indexName).execute().actionGet()
+                .getState();
+        final IndexMetaData imd = cs.getMetaData().index(indexName);
+        final ImmutableOpenMap<String, MappingMetaData> mappings = imd.getMappings();
+        final ObjectLookupContainer<String> documentTypes = mappings.keys();
+
         final List<SimpleTableDef> result = new ArrayList<SimpleTableDef>();
-        for (final String indexName : indexNames) {
-            final ClusterState cs = client.admin().cluster().prepareState().setIndices(indexName).execute().actionGet()
-                    .getState();
-            final IndexMetaData imd = cs.getMetaData().index(indexName);
-            final ImmutableOpenMap<String, MappingMetaData> mappings = imd.getMappings();
-            final ObjectLookupContainer<String> indexTypes = mappings.keys();
-            for (final Object indexType : indexTypes) {
-                final String typeName = ((ObjectCursor<?>) indexType).value.toString();
-                try {
-                    final SimpleTableDef table = detectTable(cs, indexName, typeName);
-                    result.add(table);
-                } catch (Exception e) {
-                    logger.error("Unexpected error during detectSchema for table: " + typeName, e);
-                }
+        for (final Object documentTypeCursor : documentTypes) {
+            final String documentType = ((ObjectCursor<?>) documentTypeCursor).value.toString();
+            try {
+                final SimpleTableDef table = detectTable(cs, indexName, documentType);
+                result.add(table);
+            } catch (Exception e) {
+                logger.error("Unexpected error during detectTable for document type: {}", documentType, e);
             }
-
         }
         final SimpleTableDef[] tableDefArray = (SimpleTableDef[]) result.toArray(new SimpleTableDef[result.size()]);
+        Arrays.sort(tableDefArray, new Comparator<SimpleTableDef>() {
+            @Override
+            public int compare(SimpleTableDef o1, SimpleTableDef o2) {
+                return o1.getName().compareTo(o2.getName());
+            }
+        });
+
         return tableDefArray;
     }
 
@@ -151,18 +160,18 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
      *            the ElasticSearch cluster
      * @param indexName
      *            the name of the index
-     * @param typeName
+     * @param documentType
      *            the name of the index type
      * @return a table definition for ElasticSearch.
      */
-    public static SimpleTableDef detectTable(ClusterState cs, String indexName, String typeName) throws Exception {
+    public static SimpleTableDef detectTable(ClusterState cs, String indexName, String documentType) throws Exception {
         final IndexMetaData imd = cs.getMetaData().index(indexName);
-        final MappingMetaData mappingMetaData = imd.mapping(typeName);
+        final MappingMetaData mappingMetaData = imd.mapping(documentType);
         final Map<String, Object> mp = mappingMetaData.getSourceAsMap();
         final Iterator<Map.Entry<String, Object>> it = mp.entrySet().iterator();
         final Map.Entry<String, Object> pair = it.next();
         final ElasticSearchMetaData metaData = ElasticSearchMetaDataParser.parse(pair.getValue());
-        return new SimpleTableDef(typeName, metaData.getColumnNames(), metaData.getColumnTypes());
+        return new SimpleTableDef(documentType, metaData.getColumnNames(), metaData.getColumnTypes());
     }
 
     @Override
@@ -182,8 +191,8 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
 
     @Override
     protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
-        final SearchRequestBuilder requestBuilder = elasticSearchClient.prepareSearch(
-                getIndexNameForIndexType(table.getName())).setTypes(table.getName());
+        final String documentType = table.getName();
+        final SearchRequestBuilder requestBuilder = elasticSearchClient.prepareSearch(indexName).setTypes(documentType);
         if (limitMaxRowsIsSet(maxRows)) {
             requestBuilder.setSize(maxRows);
         }
@@ -193,127 +202,17 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
 
     @Override
     protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
-        final CountResponse response = elasticSearchClient.prepareCount(getIndexNameForIndexType(table.getName()))
-                .setQuery(QueryBuilders.termQuery("_type", table.getName())).execute().actionGet();
+        if (!whereItems.isEmpty()) {
+            // not supported - will have to be done by counting client-side
+            return null;
+        }
+        String documentType = table.getName();
+        final CountResponse response = elasticSearchClient.prepareCount(indexName)
+                .setQuery(QueryBuilders.termQuery("_type", documentType)).execute().actionGet();
         return response.getCount();
     }
 
     private boolean limitMaxRowsIsSet(int maxRows) {
         return (maxRows != -1);
     }
-
-    private String getIndexNameForIndexType(String indexType) {
-        String indexName = typeAndIndexes.get(indexType);
-        if (indexName == null)
-            indexName = fetchIndexNameFromES(indexType);
-        return indexName;
-    }
-
-    private String fetchIndexNameFromES(String indexType) {
-        String theIndexName = "";
-        boolean indexNameFound = false;
-        final List<String> indexNames = getIndexNamesFromES();
-        for (String indexName : indexNames) {
-            if (!indexNameFound) {
-                final ClusterState cs = elasticSearchClient.admin().cluster().prepareState().setIndices(indexName)
-                        .execute().actionGet().getState();
-                final IndexMetaData imd = cs.getMetaData().index(indexName);
-                final ImmutableOpenMap<String, MappingMetaData> mappings = imd.getMappings();
-                final ObjectLookupContainer<String> indexTypes = mappings.keys();
-                for (final Object type : indexTypes) {
-                    final String typeName = ((ObjectCursor<?>) type).value.toString();
-                    if (typeName.equals(indexType)) {
-                        theIndexName = indexName;
-                        typeAndIndexes.put(typeName, indexName);
-                        indexNameFound = true;
-                    }
-                }
-            }
-        }
-        return theIndexName;
-    }
-
-    private List<String> getIndexNamesFromES() {
-        final List<String> indexNames = new ArrayList<String>();
-        final ClusterStateResponse clusterStateResponse = elasticSearchClient.admin().cluster().prepareState()
-                .execute().actionGet();
-        final ImmutableOpenMap<String, IndexMetaData> indexes = clusterStateResponse.getState().getMetaData()
-                .getIndices();
-        for (final ObjectCursor<String> typeCursor : indexes.keys()) {
-            indexNames.add(typeCursor.value);
-        }
-        return indexNames;
-    }
-
-    /*
-     * TODO: Implement corner cases of WHERE, GROUPBY... items that we can
-     * support natively.
-     * 
-     * @Override public DataSet executeQuery(Query query) { // Check for queries
-     * containing only simple selects and where clauses, // or if it is a
-     * COUNT(*) query. // if from clause only contains a main schema table
-     * List<FromItem> fromItems = query.getFromClause().getItems(); if
-     * (fromItems.size() == 1 && fromItems.get(0).getTable() != null &&
-     * fromItems.get(0).getTable().getSchema() == schema) { final Table table =
-     * fromItems.get(0).getTable();
-     * 
-     * // if GROUP BY, HAVING and ORDER BY clauses are not specified if
-     * (query.getGroupByClause().isEmpty() && query.getHavingClause().isEmpty()
-     * && query.getOrderByClause().isEmpty()) {
-     * 
-     * final List<FilterItem> whereItems = query.getWhereClause().getItems();
-     * 
-     * // if all of the select items are "pure" column selection boolean
-     * allSelectItemsAreColumns = true; List<SelectItem> selectItems =
-     * query.getSelectClause().getItems();
-     * 
-     * // if it is a // "SELECT [columns] FROM [table] WHERE [conditions]" //
-     * query. for (SelectItem selectItem : selectItems) { if
-     * (selectItem.getFunction() != null || selectItem.getColumn() == null) {
-     * allSelectItemsAreColumns = false; break; } }
-     * 
-     * if (allSelectItemsAreColumns) { logger.debug(
-     * "Query can be expressed in full ElasticSearch, no post processing needed."
-     * );
-     * 
-     * // prepare for a non-post-processed query Column[] columns = new
-     * Column[selectItems.size()]; for (int i = 0; i < columns.length; i++) {
-     * columns[i] = selectItems.get(i).getColumn(); }
-     * 
-     * int firstRow = (query.getFirstRow() == null ? 1 : query.getFirstRow());
-     * int maxRows = (query.getMaxRows() == null ? -1 : query.getMaxRows());
-     * 
-     * final DataSet dataSet = materializeMainSchemaTableInternal(table,
-     * columns, whereItems, firstRow, maxRows, false); return dataSet; } } }
-     * logger
-     * .debug("Query will be simplified for ElasticSearch and post processed.");
-     * return super.executeQuery(query); }
-     * 
-     * private DataSet materializeMainSchemaTableInternal(Table table, Column[]
-     * columns, List<FilterItem> whereItems, int firstRow, int maxRows, boolean
-     * queryPostProcessed) { //final SearchRequestBuilder collection =
-     * elasticSearchClient
-     * .prepareSearch(typeAndIndexes.get(table.getName())).setTypes
-     * (table.getName()); ClusterStateResponse clusterStateResponse =
-     * elasticSearchClient
-     * .admin().cluster().prepareState().execute().actionGet();
-     * ImmutableOpenMap<String,IndexMetaData> indexes =
-     * clusterStateResponse.getState().getMetaData().getIndices(); //final
-     * SearchRequestBuilder collection =
-     * elasticSearchClient.prepareSearch("twitter").setTypes("tweet1");
-     * SearchRequestBuilder requestBuilder =
-     * elasticSearchClient.prepareSearch();
-     * 
-     * if (whereItems != null && !whereItems.isEmpty()) { for (FilterItem item :
-     * whereItems) { String operandWithIndexName =
-     * item.getSelectItem().toString(); int operandNameIndexStart =
-     * operandWithIndexName.indexOf(".")+1; String operandWithoutIndexName =
-     * operandWithIndexName.substring(operandNameIndexStart);
-     * requestBuilder.setQuery(QueryBuilders.termQuery(operandWithoutIndexName,
-     * item.getOperand())); } }
-     * 
-     * SearchResponse response = requestBuilder.execute().actionGet();
-     * 
-     * return new ElasticSearchDataSet(response, columns, queryPostProcessed); }
-     */
 }

http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/72bfb77a/elasticsearch/src/test/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContextTest.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/test/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContextTest.java b/elasticsearch/src/test/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContextTest.java
index 6fcc942..89690d3 100644
--- a/elasticsearch/src/test/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContextTest.java
+++ b/elasticsearch/src/test/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContextTest.java
@@ -18,7 +18,16 @@
  */
 package org.apache.metamodel.elasticsearch;
 
-import junit.framework.TestCase;
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import javax.swing.table.TableModel;
 
 import org.apache.metamodel.DataContext;
 import org.apache.metamodel.data.DataSet;
@@ -33,31 +42,23 @@ import org.apache.metamodel.schema.Table;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-
-import javax.swing.table.TableModel;
-
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
-
-public class ElasticSearchDataContextTest extends TestCase {
-
-    private EmbeddedElasticsearchServer embeddedElasticsearchServer;
-    private Client client;
-    DataContext dataContext;
-    String indexName = "twitter";
-    String indexType1 = "tweet1";
-    String indexType2 = "tweet2";
-    String bulkIndexName = "bulktwitter";
-    String bulkIndexType = "bulktype";
-    String peopleIndexName = "peopleindex";
-    String peopleIndexType = "peopletype";
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ElasticSearchDataContextTest {
+
+    private static final String indexName = "twitter";
+    private static final String indexType1 = "tweet1";
+    private static final String indexType2 = "tweet2";
+    private static final String bulkIndexType = "bulktype";
+    private static final String peopleIndexType = "peopletype";
+    private static EmbeddedElasticsearchServer embeddedElasticsearchServer;
+    private static Client client;
+    private static DataContext dataContext;
+
+    @BeforeClass
+    public static void beforeTests() throws Exception {
         embeddedElasticsearchServer = new EmbeddedElasticsearchServer();
         client = embeddedElasticsearchServer.getClient();
         indexOneTweeterDocumentPerIndex(indexType1, 1);
@@ -72,20 +73,25 @@ public class ElasticSearchDataContextTest extends TestCase {
         indexOnePeopleDocument("male", 18, 3);
         indexOnePeopleDocument("male", 18, 4);
         indexOneTweeterDocumentPerIndex(indexType2, 1);
-        indexBulkDocuments(bulkIndexName, bulkIndexType, 10);
+        indexBulkDocuments(indexName, bulkIndexType, 10);
+        
+        // TODO: Find a better way than sleep to ensure data is in sync.
+        
         // Waiting for indexing the data....
         Thread.sleep(2000);
-        dataContext = new ElasticSearchDataContext(client);
+        dataContext = new ElasticSearchDataContext(client, indexName);
+        System.out.println("Embedded ElasticSearch server created!");
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
+    @AfterClass
+    public static void afterTests() {
         embeddedElasticsearchServer.shutdown();
+        System.out.println("Embedded ElasticSearch server shut down!");
     }
 
+    @Test
     public void testSimpleQuery() throws Exception {
-        assertEquals("[peopletype, bulktype, tweet1, tweet2]",
+        assertEquals("[bulktype, peopletype, tweet1, tweet2]",
                 Arrays.toString(dataContext.getDefaultSchema().getTableNames()));
 
         Table table = dataContext.getDefaultSchema().getTableByName("tweet1");
@@ -106,6 +112,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         }
     }
 
+    @Test
     public void testWhereColumnEqualsValues() throws Exception {
         DataSet ds = dataContext.query().from(bulkIndexType).select("user").and("message").where("user")
                 .isEquals("user4").execute();
@@ -120,26 +127,28 @@ public class ElasticSearchDataContextTest extends TestCase {
         }
     }
 
+    @Test
     public void testWhereColumnInValues() throws Exception {
         DataSet ds = dataContext.query().from(bulkIndexType).select("user").and("message").where("user")
                 .in("user4", "user5").orderBy("message").execute();
 
         try {
             assertTrue(ds.next());
-            
+
             String row1 = ds.getRow().toString();
             assertEquals("Row[values=[user4, 4]]", row1);
             assertTrue(ds.next());
-            
+
             String row2 = ds.getRow().toString();
             assertEquals("Row[values=[user5, 5]]", row2);
-            
+
             assertFalse(ds.next());
         } finally {
             ds.close();
         }
     }
 
+    @Test
     public void testGroupByQuery() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType);
 
@@ -164,6 +173,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertFalse(data.next());
     }
 
+    @Test
     public void testFilterOnNumberColumn() {
         Table table = dataContext.getDefaultSchema().getTableByName(bulkIndexType);
         Query q = dataContext.query().from(table).select("user").where("message").greaterThan(7).toQuery();
@@ -177,6 +187,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertFalse(data.next());
     }
 
+    @Test
     public void testMaxRows() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType);
         Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5);
@@ -186,6 +197,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertEquals(5, tableModel.getRowCount());
     }
 
+    @Test
     public void testCountQuery() throws Exception {
         Table table = dataContext.getDefaultSchema().getTableByName(bulkIndexType);
         Query q = new Query().selectCount().from(table);
@@ -197,6 +209,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertEquals("[10]", Arrays.toString(row));
     }
 
+    @Test
     public void testQueryForANonExistingTable() throws Exception {
         boolean thrown = false;
         try {
@@ -209,6 +222,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertTrue(thrown);
     }
 
+    @Test
     public void testQueryForAnExistingTableAndNonExistingField() throws Exception {
         indexOneTweeterDocumentPerIndex(indexType1, 1);
         boolean thrown = false;
@@ -222,7 +236,7 @@ public class ElasticSearchDataContextTest extends TestCase {
         assertTrue(thrown);
     }
 
-    private void indexBulkDocuments(String indexName, String indexType, int numberOfDocuments) {
+    private static void indexBulkDocuments(String indexName, String indexType, int numberOfDocuments) {
         BulkRequestBuilder bulkRequest = client.prepareBulk();
 
         try {
@@ -237,7 +251,7 @@ public class ElasticSearchDataContextTest extends TestCase {
 
     }
 
-    private void indexOneTweeterDocumentPerIndex(String indexType, int id) {
+    private static void indexOneTweeterDocumentPerIndex(String indexType, int id) {
         try {
             client.prepareIndex(indexName, indexType).setSource(buildTweeterJson(id)).execute().actionGet();
         } catch (Exception ex) {
@@ -245,21 +259,21 @@ public class ElasticSearchDataContextTest extends TestCase {
         }
     }
 
-    private void indexOnePeopleDocument(String gender, int age, int id) {
+    private static void indexOnePeopleDocument(String gender, int age, int id) {
         try {
-            client.prepareIndex(peopleIndexName, peopleIndexType).setSource(buildPeopleJson(gender, age, id)).execute()
+            client.prepareIndex(indexName, peopleIndexType).setSource(buildPeopleJson(gender, age, id)).execute()
                     .actionGet();
         } catch (Exception ex) {
             System.out.println("Exception indexing documents!!!!!");
         }
     }
 
-    private XContentBuilder buildTweeterJson(int elementId) throws Exception {
+    private static XContentBuilder buildTweeterJson(int elementId) throws Exception {
         return jsonBuilder().startObject().field("user", "user" + elementId).field("postDate", new Date())
                 .field("message", elementId).endObject();
     }
 
-    private XContentBuilder buildPeopleJson(String gender, int age, int elementId) throws Exception {
+    private static XContentBuilder buildPeopleJson(String gender, int age, int elementId) throws Exception {
         return jsonBuilder().startObject().field("gender", gender).field("age", age).field("id", elementId).endObject();
     }
 


[3/3] git commit: METAMODEL-77: Added separate dependency for JDK6 since latest ES requires Java 7.

Posted by ka...@apache.org.
METAMODEL-77: Added separate dependency for JDK6 since latest ES
requires Java 7.

Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/6aeb3507
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/6aeb3507
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/6aeb3507

Branch: refs/heads/master
Commit: 6aeb35073d065df6847c3a8eb0378d799ef32d78
Parents: 83c43cb
Author: Kasper Sørensen <i....@gmail.com>
Authored: Wed Sep 24 09:47:19 2014 +0200
Committer: Kasper Sørensen <i....@gmail.com>
Committed: Wed Sep 24 09:47:19 2014 +0200

----------------------------------------------------------------------
 elasticsearch/pom.xml | 134 +++++++++++++++++++++++++--------------------
 1 file changed, 76 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/6aeb3507/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml
index 4471f1f..1ab40a4 100644
--- a/elasticsearch/pom.xml
+++ b/elasticsearch/pom.xml
@@ -1,65 +1,83 @@
 <?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
+<!-- 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/maven-v4_0_0.xsd">
+	<parent>
+		<artifactId>MetaModel</artifactId>
+		<groupId>org.apache.metamodel</groupId>
+		<version>4.3-incubating-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<artifactId>MetaModel-elasticsearch</artifactId>
+	<name>MetaModel module for Elasticsearch analytics engine</name>
 
-  http://www.apache.org/licenses/LICENSE-2.0
+	<properties>
+		<elasticsearch.latest.version>1.3.2</elasticsearch.latest.version>
+		<elasticsearch.jdk6.version>0.90.13</elasticsearch.jdk6.version>
+	</properties>
 
-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/maven-v4_0_0.xsd">
-    <parent>
-        <artifactId>MetaModel</artifactId>
-        <groupId>org.apache.metamodel</groupId>
-        <version>4.3-incubating-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-    <artifactId>MetaModel-elasticsearch</artifactId>
-    <name>MetaModel module for Elasticsearch analytics engine</name>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.metamodel</groupId>
+			<artifactId>MetaModel-core</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+		</dependency>
+		<!-- test -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
 
-    <properties>
-        <elasticsearch.version>1.3.2</elasticsearch.version>
-        <commons-io.version>2.4</commons-io.version>
-    </properties>
+	<profiles>
+		<profile>
+			<id>latest</id>
+			<activation>
+				<jdk>!1.6</jdk>
+			</activation>
+			<dependencies>
+				<!-- elasticsearch -->
+				<dependency>
+					<groupId>org.elasticsearch</groupId>
+					<artifactId>elasticsearch</artifactId>
+					<version>${elasticsearch.latest.version}</version>
+				</dependency>
+			</dependencies>
+		</profile>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.metamodel</groupId>
-            <artifactId>MetaModel-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <!-- elasticsearch -->
-        <dependency>
-            <groupId>org.elasticsearch</groupId>
-            <artifactId>elasticsearch</artifactId>
-            <version>${elasticsearch.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>${commons-io.version}</version>
-        </dependency>
-        <!-- test -->
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
+		<profile>
+			<id>jdk6</id>
+			<activation>
+				<jdk>1.6</jdk>
+			</activation>
+			<dependencies>
+				<!-- elasticsearch -->
+				<dependency>
+					<groupId>org.elasticsearch</groupId>
+					<artifactId>elasticsearch</artifactId>
+					<version>${elasticsearch.jdk6.version}</version>
+				</dependency>
+			</dependencies>
+		</profile>
 
-    </dependencies>
+	</profiles>
 </project>
\ No newline at end of file


[2/3] git commit: Using index name as schema name

Posted by ka...@apache.org.
Using index name as schema name

Project: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/commit/83c43cbb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/tree/83c43cbb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metamodel/diff/83c43cbb

Branch: refs/heads/master
Commit: 83c43cbba4e8394f92b7549792a0bbde5f65d82b
Parents: 72bfb77
Author: Kasper Sørensen <i....@gmail.com>
Authored: Wed Sep 24 09:42:02 2014 +0200
Committer: Kasper Sørensen <i....@gmail.com>
Committed: Wed Sep 24 09:42:02 2014 +0200

----------------------------------------------------------------------
 .../apache/metamodel/elasticsearch/ElasticSearchDataContext.java | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/83c43cbb/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java b/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
index c38c0fa..651a828 100644
--- a/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
+++ b/elasticsearch/src/main/java/org/apache/metamodel/elasticsearch/ElasticSearchDataContext.java
@@ -71,8 +71,6 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
 
     private static final Logger logger = LoggerFactory.getLogger(ElasticSearchDataContext.class);
 
-    private static final String ES_CLUSTER_NAME = "cluster.name";
-
     private final Client elasticSearchClient;
     private final SimpleTableDef[] tableDefs;
     private final String indexName;
@@ -186,7 +184,7 @@ public class ElasticSearchDataContext extends QueryPostprocessDataContext implem
 
     @Override
     protected String getMainSchemaName() throws MetaModelException {
-        return elasticSearchClient.settings().get(ES_CLUSTER_NAME);
+        return indexName;
     }
 
     @Override