All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.apache.calcite.schema.impl.AbstractSchema Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * 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 com.hazelcast.org.apache.calcite.schema.impl;

import com.hazelcast.org.apache.calcite.linq4j.tree.Expression;
import com.hazelcast.org.apache.calcite.rel.type.RelProtoDataType;
import com.hazelcast.org.apache.calcite.schema.Function;
import com.hazelcast.org.apache.calcite.schema.Schema;
import com.hazelcast.org.apache.calcite.schema.SchemaFactory;
import com.hazelcast.org.apache.calcite.schema.SchemaPlus;
import com.hazelcast.org.apache.calcite.schema.SchemaVersion;
import com.hazelcast.org.apache.calcite.schema.Schemas;
import com.hazelcast.org.apache.calcite.schema.Table;

import com.hazelcast.com.google.common.collect.ImmutableMap;
import com.hazelcast.com.google.common.collect.ImmutableMultimap;
import com.hazelcast.com.google.common.collect.Multimap;

import com.hazelcast.org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import static java.util.Objects.requireNonNull;

/**
 * Abstract implementation of {@link Schema}.
 *
 * 

Behavior is as follows:

*
    *
  • The schema has no tables unless you override * {@link #getTableMap()}.
  • *
  • The schema has no functions unless you override * {@link #getFunctionMultimap()}.
  • *
  • The schema has no sub-schemas unless you override * {@link #getSubSchemaMap()}.
  • *
  • The schema is mutable unless you override * {@link #isMutable()}.
  • *
  • The name and parent schema are as specified in the constructor * arguments.
  • *
*/ public class AbstractSchema implements Schema { public AbstractSchema() { } @Override public boolean isMutable() { return true; } @Override public Schema snapshot(SchemaVersion version) { return this; } @Override public Expression getExpression(@Nullable SchemaPlus parentSchema, String name) { requireNonNull(parentSchema, "parentSchema"); return Schemas.subSchemaExpression(parentSchema, name, getClass()); } /** * Returns a map of tables in this schema by name. * *

The implementations of {@link #getTableNames()} * and {@link #getTable(String)} depend on this map. * The default implementation of this method returns the empty map. * Override this method to change their behavior.

* * @return Map of tables in this schema by name */ protected Map getTableMap() { return ImmutableMap.of(); } @Override public final Set getTableNames() { //noinspection RedundantCast return (Set) getTableMap().keySet(); } @Override public final @Nullable Table getTable(String name) { return getTableMap().get(name); } /** * Returns a map of types in this schema by name. * *

The implementations of {@link #getTypeNames()} * and {@link #getType(String)} depend on this map. * The default implementation of this method returns the empty map. * Override this method to change their behavior.

* * @return Map of types in this schema by name */ protected Map getTypeMap() { return ImmutableMap.of(); } @Override public @Nullable RelProtoDataType getType(String name) { return getTypeMap().get(name); } @Override public Set getTypeNames() { //noinspection RedundantCast return (Set) getTypeMap().keySet(); } /** * Returns a multi-map of functions in this schema by name. * It is a multi-map because functions are overloaded; there may be more than * one function in a schema with a given name (as long as they have different * parameter lists). * *

The implementations of {@link #getFunctionNames()} * and {@link Schema#getFunctions(String)} depend on this map. * The default implementation of this method returns the empty multi-map. * Override this method to change their behavior.

* * @return Multi-map of functions in this schema by name */ protected Multimap getFunctionMultimap() { return ImmutableMultimap.of(); } @Override public final Collection getFunctions(String name) { return getFunctionMultimap().get(name); // never null } @Override public final Set getFunctionNames() { return getFunctionMultimap().keySet(); } /** * Returns a map of sub-schemas in this schema by name. * *

The implementations of {@link #getSubSchemaNames()} * and {@link #getSubSchema(String)} depend on this map. * The default implementation of this method returns the empty map. * Override this method to change their behavior.

* * @return Map of sub-schemas in this schema by name */ protected Map getSubSchemaMap() { return ImmutableMap.of(); } @Override public final Set getSubSchemaNames() { //noinspection RedundantCast return (Set) getSubSchemaMap().keySet(); } @Override public final @Nullable Schema getSubSchema(String name) { return getSubSchemaMap().get(name); } /** Schema factory that creates an * {@link com.hazelcast.org.apache.calcite.schema.impl.AbstractSchema}. */ public static class Factory implements SchemaFactory { public static final Factory INSTANCE = new Factory(); private Factory() {} @Override public Schema create(SchemaPlus parentSchema, String name, Map operand) { return new AbstractSchema(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy