1 Star 1 Fork 12

fnet / solr-sql

forked from 白乔 / solr-sql 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
BSD-3-Clause

中文版: https://github.com/bluejoe2008/solr-sql/blob/master/README_CN.md

solr-sql

solr-sql provides sql interfaces for solr cloud(http://lucene.apache.org/solr/), by which developers can operate on solr cloud via JDBC protocols.

On the same time, solr-sql is an Apache Calcite(see http://calcite.apache.org) adapter for solr.

about project

solr-sql is written in Scala, which generates JVM byte codes like Java.

This project is hosted on http://github.com/bluejoe2008/solr-sql.

So, if you are a Java developer, do not hesitate to choose solr-sql, because it is easy to be referenced by Java code. Also the test cases are written in Java(see https://github.com/bluejoe2008/solr-sql/blob/master/src/java/test/SolrSqlQueryTest.java).

If you are interested in source codes, manybe you need install a ScalaIDE(http://scala-ide.org/), or scala plugins for eclipse.

solr-sql uses Maven to manage libary dependencies, it is a normal Maven project.

import solr-sql

use maven to import solr-sql:

<dependency>
  <groupId>com.github.bluejoe2008</groupId>
  <artifactId>solr-sql</artifactId>
  <version>0.9</version>
</dependency>

JDBC client code

example code:

Properties info = new Properties();
info.setProperty("lex", "JAVA");
Connection connection = DriverManager.getConnection(
		"jdbc:calcite:model=src/java/test/model.json", info);

Statement statement = connection.createStatement();
String sql = "select * from docs where not (age>35 and name='bluejoe')";
ResultSet resultSet = statement.executeQuery(sql);

this illustrates how to connect to a solr 'database' in JDBC client manners, the schema of 'database' is defined in file 'src/java/test/model.json'.

table definition

the file 'src/java/test/model.json' shows an example schema definition as below:

{
	version: '1.0',
	defaultSchema: 'solr',
	schemas:
	[
		{
			name: 'solr',
			tables:
			[
				{
					name: 'docs',
					type: 'custom',
					factory: 'org.apache.calcite.adapter.solr.SolrTableFactory',
					operand:
					{
						solrServerURL: 'http://bluejoe1:8983/solr/collection1',
						solrCollection: 'collection1',	
						//solrZkHosts: 'bluejoe1:9983',
						columns:'id integer, name char, age integer',
						columnMapping: 'name->name_s, age->age_i'
					}
				}
			]
		}
	]
}

this defines a custom table named 'docs', several arguments can be defined in the operand field:

  • solrServerURL: solr server url, e.g. 'http://bluejoe1:8983/solr/collection1'
  • solrCollection: collection name, e.g. 'collection1'
  • solrZkHosts: zookeeper hosts employed by solr cloud, e.g. 'bluejoe1:9983'
  • columns: comma seperated column definitions, each column is describled in format 'column_name column_type_name', e.g. 'id integer, name char, age integer'
  • columnMapping: comma seperated column mappings, each column mapping is describled in format 'columnName->field_name_in_solr_document', e.g. 'name->name_s, age->age_i'
  • pageSize: solr-sql does not retrieve all results on querying, for example, it only retrieves first 50 results, if the sql engine requests for more, it retrieves for next 50 results. pageSize defines the size of each query, default value is 50.

run tests

https://github.com/bluejoe2008/solr-sql/blob/master/src/java/test/SolrSqlQueryTest.java shows how to connect to a JDBC source of solr.

https://github.com/bluejoe2008/solr-sql/blob/master/src/java/test/SqlTranslatorTest.java tests if the translation from SQL filters to Solr filters is right, like:

Assert.assertEquals("age_i:{20 TO *}",
	trans("select * from docs where age>20"));

SqlFilter2SolrFilterTranslator

a SqlFilter2SolrFilterTranslator translates a SQL filter to a Solr filter. a SQL filter is represented by a Calcite RexNode object, and a solr filter is represented by a SolrFilter object. There are serveral SolrFilters defined in this project:

  • AndSolrFilter
  • NotSolrFilter
  • OrSolrFilter
  • GtSolrFilter
  • NotNullSolrFilter
  • IsNullSolrFilter
  • EqualsSolrFilter
  • LikeSolrFilter
  • NotEqualsSolrFilter
  • GeSolrFilter
  • LeSolrFilter
  • LtSolrFilter
  • UnrecognizedSolrFilter
Copyright (c) 2016, cas-bigdatalab All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of solr-sql nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

针对Solr的SQL查询引擎 expand collapse
Scala
BSD-3-Clause
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
Scala
1
https://gitee.com/fnet/solr-sql.git
git@gitee.com:fnet/solr-sql.git
fnet
solr-sql
solr-sql
master

Search