Class ElasticsearchTable
- java.lang.Object
-
- org.apache.calcite.schema.impl.AbstractTable
-
- org.apache.calcite.adapter.java.AbstractQueryableTable
-
- org.apache.calcite.adapter.elasticsearch.ElasticsearchTable
-
- All Implemented Interfaces:
QueryableTable
,Table
,TranslatableTable
,Wrapper
public class ElasticsearchTable extends AbstractQueryableTable implements TranslatableTable
Table based on an Elasticsearch type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ElasticsearchTable.ElasticsearchQueryable<T>
Implementation ofQueryable
based on aElasticsearchTable
.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
AGGREGATIONS
Used for constructing (possibly nested) Elastic aggregation nodes.private java.lang.String
indexName
private static org.slf4j.Logger
LOGGER
(package private) com.fasterxml.jackson.databind.ObjectMapper
mapper
private ElasticsearchTransport
transport
private java.lang.String
typeName
private ElasticsearchVersion
version
-
Fields inherited from class org.apache.calcite.adapter.java.AbstractQueryableTable
elementType
-
-
Constructor Summary
Constructors Constructor Description ElasticsearchTable(ElasticsearchTransport transport)
Creates an ElasticsearchTable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Enumerable<java.lang.Object>
aggregate(java.util.List<java.lang.String> ops, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.util.Map.Entry<java.lang.String,RelFieldCollation.Direction>> sort, java.util.List<java.lang.String> groupBy, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> aggregations, java.lang.Long offset, java.lang.Long fetch)
<T> Queryable<T>
asQueryable(QueryProvider queryProvider, SchemaPlus schema, java.lang.String tableName)
Converts this table into aQueryable
.private Enumerable<java.lang.Object>
find(java.util.List<java.lang.String> ops, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.util.Map.Entry<java.lang.String,RelFieldCollation.Direction>> sort, java.util.List<java.lang.String> groupBy, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> aggregations, java.lang.Long offset, java.lang.Long fetch)
Executes a "find" operation on the underlying type.RelDataType
getRowType(RelDataTypeFactory relDataTypeFactory)
Returns this table's row type.(package private) java.lang.String
scriptedFieldPrefix()
In ES 5.x scripted fields start withparams._source.foo
while in ES2.x_source.foo
.RelNode
toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)
Converts this table into arelational expression
.java.lang.String
toString()
-
Methods inherited from class org.apache.calcite.adapter.java.AbstractQueryableTable
getElementType, getExpression
-
Methods inherited from class org.apache.calcite.schema.impl.AbstractTable
getJdbcTableType, getStatistic, isRolledUp, rolledUpColumnValidInsideAgg, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.schema.Table
getJdbcTableType, getStatistic, isRolledUp, rolledUpColumnValidInsideAgg
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
AGGREGATIONS
private static final java.lang.String AGGREGATIONS
Used for constructing (possibly nested) Elastic aggregation nodes.- See Also:
- Constant Field Values
-
version
private final ElasticsearchVersion version
-
indexName
private final java.lang.String indexName
-
typeName
private final java.lang.String typeName
-
mapper
final com.fasterxml.jackson.databind.ObjectMapper mapper
-
transport
private final ElasticsearchTransport transport
-
-
Constructor Detail
-
ElasticsearchTable
ElasticsearchTable(ElasticsearchTransport transport)
Creates an ElasticsearchTable.
-
-
Method Detail
-
scriptedFieldPrefix
java.lang.String scriptedFieldPrefix()
In ES 5.x scripted fields start withparams._source.foo
while in ES2.x_source.foo
. Helper method to build correct query based on runtime version of elastic. Used to keep backwards compatibility with ES2.- Returns:
- string to be used for scripted fields
- See Also:
- _source variable, Scripted Fields
-
find
private Enumerable<java.lang.Object> find(java.util.List<java.lang.String> ops, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.util.Map.Entry<java.lang.String,RelFieldCollation.Direction>> sort, java.util.List<java.lang.String> groupBy, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> aggregations, java.lang.Long offset, java.lang.Long fetch) throws java.io.IOException
Executes a "find" operation on the underlying type.For example,
client.prepareSearch(index).setTypes(type) .setSource("{\"fields\" : [\"state\"]}")
- Parameters:
ops
- List of operations represented as Json strings.fields
- List of fields to project; or null to return mapsort
- list of fields to sort and their direction (asc/desc)aggregations
- aggregation functions- Returns:
- Enumerator of results
- Throws:
java.io.IOException
-
aggregate
private Enumerable<java.lang.Object> aggregate(java.util.List<java.lang.String> ops, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.util.Map.Entry<java.lang.String,RelFieldCollation.Direction>> sort, java.util.List<java.lang.String> groupBy, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> aggregations, java.lang.Long offset, java.lang.Long fetch) throws java.io.IOException
- Throws:
java.io.IOException
-
getRowType
public RelDataType getRowType(RelDataTypeFactory relDataTypeFactory)
Description copied from interface:Table
Returns this table's row type.This is a struct type whose fields describe the names and types of the columns in this table.
The implementer must use the type factory provided. This ensures that the type is converted into a canonical form; other equal types in the same query will use the same object.
- Specified by:
getRowType
in interfaceTable
- Parameters:
relDataTypeFactory
- Type factory with which to create the type- Returns:
- Row type
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
asQueryable
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, java.lang.String tableName)
Description copied from interface:QueryableTable
Converts this table into aQueryable
.- Specified by:
asQueryable
in interfaceQueryableTable
-
toRel
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)
Description copied from interface:TranslatableTable
Converts this table into arelational expression
.- Specified by:
toRel
in interfaceTranslatableTable
-
-