Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.adapter.java.AbstractQueryableTable;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.linq4j.QueryProvider;
import org.apache.calcite.linq4j.Queryable;
import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTableQueryable;
import org.apache.calcite.sql.type.SqlTypeName;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Table based on an Elasticsearch index.
*/
public class ElasticsearchTable extends AbstractQueryableTable implements TranslatableTable {
private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchTable.class);
/**
* Used for constructing (possibly nested) Elastic aggregation nodes.
*/
private static final String AGGREGATIONS = "aggregations";
private final ElasticsearchVersion version;
private final String indexName;
final ObjectMapper mapper;
final ElasticsearchTransport transport;
/**
* Creates an ElasticsearchTable.
*/
ElasticsearchTable(ElasticsearchTransport transport) {
super(Object[].class);
this.transport = Objects.requireNonNull(transport, "transport");
this.version = transport.version;
this.indexName = transport.indexName;
this.mapper = transport.mapper();
}
/**
* In ES 5.x scripted fields start with {@code params._source.foo} while in ES2.x
* {@code _source.foo}. Helper method to build correct query based on runtime version of elastic.
* Used to keep backwards compatibility with ES2.
*
* @see _source variable
* @see Scripted Fields
* @return string to be used for scripted fields
*/
String scriptedFieldPrefix() {
// ES2 vs ES5 scripted field difference
return version == ElasticsearchVersion.ES2
? ElasticsearchConstants.SOURCE_GROOVY
: ElasticsearchConstants.SOURCE_PAINLESS;
}
/**
* Executes a "find" operation on the underlying index.
*
* @param ops List of operations represented as Json strings.
* @param fields List of fields to project; or null to return map
* @param sort list of fields to sort and their direction (asc/desc)
* @param aggregations aggregation functions
* @return Enumerator of results
*/
private Enumerable