-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-2376] Unify ES2 and ES5 adapters. Migrate to low-level ES re…
…st client as main transport. (Andrei Sereda) == Major change to elastic search adapter(s) 1. Combine ES2 and ES5 under single maven module (called elasticsearch). Move shared ES source from core to separate elasticsearch module. 2. Migrate transport layer to low-level rest client. There are no more heavy core server-side ES dependencies (like Lucene, Netty etc.) in adapter, just apache http client and apache codecs. Native Transport client will be removed by the vendor in the next release (ES7-8). 3. Manually parse search results using jackson JSON library (this is already a transitive dependency from core) == Expected breaking changes for clients: 1. Change class names of Schema and SchemaFactory. They don't contain ES major version number anymore (2, 5, 6 etc.): - ElasticsearchSchemaFactory(new) vs Elasticsearch{2|5}SchemaFactory (old) - ElasticsearchSchema(new) vs Elasticsearch{2|5}Schema (old) - changed package name(s) This affects existing configurations (especially JSON files) 2. There is a single maven module elasticsearch. elasticsearch2 and elasticsearch5 are removed. Client will have to manually update their artifact dependencies. Close #744
- Loading branch information
1 parent
195414d
commit 0204f28
Showing
48 changed files
with
923 additions
and
2,701 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
core/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
core/src/main/java/org/apache/calcite/adapter/elasticsearch/package-info.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...arch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchEnumerators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* 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.calcite.adapter.elasticsearch; | ||
|
||
import org.apache.calcite.avatica.util.DateTimeUtils; | ||
import org.apache.calcite.linq4j.function.Function1; | ||
import org.apache.calcite.linq4j.tree.Primitive; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Util functions which convert | ||
* {@link org.apache.calcite.adapter.elasticsearch.ElasticsearchSearchResult.SearchHit} | ||
* into calcite specific return type (map, object[], list etc.) | ||
*/ | ||
class ElasticsearchEnumerators { | ||
|
||
private ElasticsearchEnumerators() {} | ||
|
||
private static Function1<ElasticsearchSearchResult.SearchHit, Map> mapGetter() { | ||
return new Function1<ElasticsearchSearchResult.SearchHit, Map>() { | ||
public Map apply(ElasticsearchSearchResult.SearchHit hits) { | ||
return hits.sourceOrFields(); | ||
} | ||
}; | ||
} | ||
|
||
private static Function1<ElasticsearchSearchResult.SearchHit, Object> singletonGetter( | ||
final String fieldName, | ||
final Class fieldClass) { | ||
return new Function1<ElasticsearchSearchResult.SearchHit, Object>() { | ||
public Object apply(ElasticsearchSearchResult.SearchHit hits) { | ||
return convert(hits.sourceOrFields(), fieldClass); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Function that extracts a given set of fields from elastic search result | ||
* objects. | ||
* | ||
* @param fields List of fields to project | ||
* | ||
* @return function that converts the search result into a generic array | ||
*/ | ||
private static Function1<ElasticsearchSearchResult.SearchHit, Object[]> listGetter( | ||
final List<Map.Entry<String, Class>> fields) { | ||
return new Function1<ElasticsearchSearchResult.SearchHit, Object[]>() { | ||
public Object[] apply(ElasticsearchSearchResult.SearchHit hit) { | ||
Object[] objects = new Object[fields.size()]; | ||
for (int i = 0; i < fields.size(); i++) { | ||
final Map.Entry<String, Class> field = fields.get(i); | ||
final String name = field.getKey(); | ||
final Class type = field.getValue(); | ||
objects[i] = convert(hit.value(name), type); | ||
} | ||
return objects; | ||
} | ||
}; | ||
} | ||
|
||
static Function1<ElasticsearchSearchResult.SearchHit, Object> getter( | ||
List<Map.Entry<String, Class>> fields) { | ||
//noinspection unchecked | ||
return fields == null | ||
? (Function1) mapGetter() | ||
: fields.size() == 1 | ||
? singletonGetter(fields.get(0).getKey(), fields.get(0).getValue()) | ||
: (Function1) listGetter(fields); | ||
} | ||
|
||
private static Object convert(Object o, Class clazz) { | ||
if (o == null) { | ||
return null; | ||
} | ||
Primitive primitive = Primitive.of(clazz); | ||
if (primitive != null) { | ||
clazz = primitive.boxClass; | ||
} else { | ||
primitive = Primitive.ofBox(clazz); | ||
} | ||
if (clazz.isInstance(o)) { | ||
return o; | ||
} | ||
if (o instanceof Date && primitive != null) { | ||
o = ((Date) o).getTime() / DateTimeUtils.MILLIS_PER_DAY; | ||
} | ||
if (o instanceof Number && primitive != null) { | ||
return primitive.number((Number) o); | ||
} | ||
return o; | ||
} | ||
} | ||
|
||
// End ElasticsearchEnumerators.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.