Class MongoTable
- java.lang.Object
-
- org.apache.calcite.schema.impl.AbstractTable
-
- org.apache.calcite.adapter.java.AbstractQueryableTable
-
- org.apache.calcite.adapter.mongodb.MongoTable
-
- All Implemented Interfaces:
QueryableTable
,Table
,TranslatableTable
,Wrapper
public class MongoTable extends AbstractQueryableTable implements TranslatableTable
Table based on a MongoDB collection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MongoTable.MongoQueryable<T>
Implementation ofQueryable
based on aMongoTable
.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
collectionName
-
Fields inherited from class org.apache.calcite.adapter.java.AbstractQueryableTable
elementType
-
-
Constructor Summary
Constructors Constructor Description MongoTable(java.lang.String collectionName)
Creates a MongoTable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Enumerable<java.lang.Object>
aggregate(com.mongodb.client.MongoDatabase mongoDb, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.lang.String> operations)
Executes an "aggregate" operation on the underlying collection.<T> Queryable<T>
asQueryable(QueryProvider queryProvider, SchemaPlus schema, java.lang.String tableName)
Converts this table into aQueryable
.private Enumerable<java.lang.Object>
find(com.mongodb.client.MongoDatabase mongoDb, java.lang.String filterJson, java.lang.String projectJson, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields)
Executes a "find" operation on the underlying collection.RelDataType
getRowType(RelDataTypeFactory typeFactory)
Returns this table's row type.private static java.lang.Integer
parseIntString(java.lang.String valueString)
Helper method to strip non-numerics from a string.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
-
-
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getRowType
public RelDataType getRowType(RelDataTypeFactory typeFactory)
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:
typeFactory
- Type factory with which to create the type- Returns:
- Row type
-
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
-
find
private Enumerable<java.lang.Object> find(com.mongodb.client.MongoDatabase mongoDb, java.lang.String filterJson, java.lang.String projectJson, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields)
Executes a "find" operation on the underlying collection.For example,
zipsTable.find("{state: 'OR'}", "{city: 1, zipcode: 1}")
- Parameters:
mongoDb
- MongoDB connectionfilterJson
- Filter JSON string, or nullprojectJson
- Project JSON string, or nullfields
- List of fields to project; or null to return map- Returns:
- Enumerator of results
-
aggregate
private Enumerable<java.lang.Object> aggregate(com.mongodb.client.MongoDatabase mongoDb, java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Class>> fields, java.util.List<java.lang.String> operations)
Executes an "aggregate" operation on the underlying collection.For example:
zipsTable.aggregate( "{$filter: {state: 'OR'}", "{$group: {_id: '$city', c: {$sum: 1}, p: {$sum: '$pop'}}}")
- Parameters:
mongoDb
- MongoDB connectionfields
- List of fields to project; or null to return mapoperations
- One or more JSON strings- Returns:
- Enumerator of results
-
parseIntString
private static java.lang.Integer parseIntString(java.lang.String valueString)
Helper method to strip non-numerics from a string.Currently used to determine mongod versioning numbers from buildInfo.versionArray for use in aggregate method logic.
-
-