metamodel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashish-m-yh <...@git.apache.org>
Subject [GitHub] metamodel pull request: Solr connector added to existing DataConte...
Date Sun, 26 Apr 2015 17:04:37 GMT
Github user ashish-m-yh commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/16#discussion_r29111608
  
    --- Diff: solr/src/main/java/org/apache/metamodel/solr/SolrDataContext.java ---
    @@ -0,0 +1,429 @@
    +/**
    + * 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.solr;
    +
    +import java.io.InputStreamReader;
    +import java.io.IOException;
    +import java.lang.reflect.Method;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Comparator;
    +import java.util.HashMap;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.http.HttpResponse;
    +import org.apache.http.client.HttpClient;
    +import org.apache.http.client.methods.HttpGet;
    +import org.apache.http.impl.client.DefaultHttpClient;
    +import org.apache.metamodel.DataContext;
    +import org.apache.metamodel.MetaModelException;
    +import org.apache.metamodel.query.Query;
    +import org.apache.metamodel.QueryPostprocessDataContext;
    +import org.apache.metamodel.data.DataSet;
    +import org.apache.metamodel.data.DataSetHeader;
    +import org.apache.metamodel.data.Row;
    +import org.apache.metamodel.data.SimpleDataSetHeader;
    +import org.apache.metamodel.query.FilterClause;
    +import org.apache.metamodel.query.FilterItem;
    +import org.apache.metamodel.query.GroupByItem;
    +import org.apache.metamodel.query.OrderByItem;
    +import org.apache.metamodel.query.SelectItem;
    +import org.apache.metamodel.query.LogicalOperator;
    +import org.apache.metamodel.query.OperatorType;
    +import org.apache.metamodel.query.FunctionType;
    +import org.apache.metamodel.schema.Column;
    +import org.apache.metamodel.schema.ColumnType;
    +import org.apache.metamodel.schema.MutableColumn;
    +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.apache.solr.client.solrj.SolrQuery;
    +import org.apache.solr.client.solrj.SolrQuery.ORDER;
    +import org.apache.solr.client.solrj.SolrServerException;
    +import org.apache.solr.client.solrj.impl.HttpSolrServer;
    +import org.apache.solr.client.solrj.response.QueryResponse;
    +import org.apache.solr.client.solrj.response.FacetField;
    +import org.apache.solr.common.SolrDocumentList;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.ObjectReader;
    +
    +/**
    + * DataContext implementation for ElasticSearch analytics engine.
    + * 
    + * 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>
    + * 
    + * 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 SolrDataContext extends QueryPostprocessDataContext implements
    +		DataContext {
    +
    +	private static final Logger logger = LoggerFactory
    +			.getLogger(SolrDataContext.class);
    +
    +	public static final String FIELD_ID = "_id";
    +
    +	private final SimpleTableDef tableDef;
    +	private final String indexName;
    +	private final String url;
    +
    +	private SolrQuery query = new SolrQuery();
    +
    +	private static enum queryTypes {
    +		ROW, FACET
    +	};
    +
    +	private static final int MAX_RETRIES = 0;
    +	private static final int SOCK_TIMEOUT = 1000;
    +	private static final int CONN_TIMEOUT = 5000;
    +	private static final int DEFAULT_LIMIT = 1000;
    +
    +	public SolrDataContext(String url, String indexName) {
    +		this.url = url;
    +		this.indexName = indexName;
    +		this.tableDef = detectSchema(url, indexName);
    +	}
    +
    +	private SimpleTableDef detectSchema(String url, String indexName) {
    +		SimpleTableDef tableDef = null;
    +
    +		url += "/schema";
    +
    +		try {
    +			HttpClient httpclient = new DefaultHttpClient();
    +			HttpGet request = new HttpGet(url);
    +			HttpResponse response = httpclient.execute(request);
    +
    +			InputStreamReader inputStream = new InputStreamReader(response
    +					.getEntity().getContent());
    +
    +			ObjectReader reader = new ObjectMapper().reader(HashMap.class);
    --- End diff --
    
    There is no documented API for this. I have put in place necessary exception handling.



---
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.
---

Mime
View raw message