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

com.hazelcast.org.apache.calcite.sql.type.SqlTypeFamily Maven / Gradle / Ivy

There is a newer version: 5.4.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 com.hazelcast.com.liance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.com.hazelcast.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.sql.type;

import com.hazelcast.org.apache.calcite.avatica.util.TimeUnit;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeFactory;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeFamily;
import com.hazelcast.org.apache.calcite.sql.SqlIntervalQualifier;
import com.hazelcast.org.apache.calcite.sql.parser.SqlParserPos;

import com.hazelcast.com.google.com.hazelcast.com.on.collect.ImmutableList;
import com.hazelcast.com.google.com.hazelcast.com.on.collect.ImmutableMap;

import java.sql.Types;
import java.util.Collection;
import java.util.Map;

/**
 * SqlTypeFamily provides SQL type categorization.
 *
 * 

The primary family categorization is a com.hazelcast.com.lete disjoint * partitioning of SQL types into families, where two types are members of the * same primary family iff instances of the two types can be the operands of an * SQL equality predicate such as WHERE v1 = v2. Primary families * are returned by RelDataType.getFamily(). * *

There is also a secondary family categorization which overlaps * with the primary categorization. It is used in type strategies for more * specific or more general categorization than the primary families. Secondary * families are never returned by RelDataType.getFamily(). */ public enum SqlTypeFamily implements RelDataTypeFamily { // Primary families. CHARACTER, BINARY, NUMERIC, DATE, TIME, TIMESTAMP, BOOLEAN, INTERVAL_YEAR_MONTH, INTERVAL_DAY_TIME, // Secondary families. STRING, APPROXIMATE_NUMERIC, EXACT_NUMERIC, DECIMAL, INTEGER, DATETIME, DATETIME_INTERVAL, MULTISET, ARRAY, MAP, NULL, ANY, CURSOR, COLUMN_LIST, GEO; private static final Map JDBC_TYPE_TO_FAMILY = ImmutableMap.builder() // Not present: // SqlTypeName.MULTISET shares Types.ARRAY with SqlTypeName.ARRAY; // SqlTypeName.MAP has no corresponding JDBC type // SqlTypeName.COLUMN_LIST has no corresponding JDBC type .put(Types.BIT, NUMERIC) .put(Types.TINYINT, NUMERIC) .put(Types.SMALLINT, NUMERIC) .put(Types.BIGINT, NUMERIC) .put(Types.INTEGER, NUMERIC) .put(Types.NUMERIC, NUMERIC) .put(Types.DECIMAL, NUMERIC) .put(Types.FLOAT, NUMERIC) .put(Types.REAL, NUMERIC) .put(Types.DOUBLE, NUMERIC) .put(Types.CHAR, CHARACTER) .put(Types.VARCHAR, CHARACTER) .put(Types.LONGVARCHAR, CHARACTER) .put(Types.CLOB, CHARACTER) .put(Types.BINARY, BINARY) .put(Types.VARBINARY, BINARY) .put(Types.LONGVARBINARY, BINARY) .put(Types.BLOB, BINARY) .put(Types.DATE, DATE) .put(Types.TIME, TIME) .put(ExtraSqlTypes.TIME_WITH_TIMEZONE, TIME) .put(Types.TIMESTAMP, TIMESTAMP) .put(ExtraSqlTypes.TIMESTAMP_WITH_TIMEZONE, TIMESTAMP) .put(Types.BOOLEAN, BOOLEAN) .put(ExtraSqlTypes.REF_CURSOR, CURSOR) .put(Types.ARRAY, ARRAY) .build(); /** * Gets the primary family containing a JDBC type. * * @param jdbcType the JDBC type of interest * @return containing family */ public static SqlTypeFamily getFamilyForJdbcType(int jdbcType) { return JDBC_TYPE_TO_FAMILY.get(jdbcType); } /** * @return collection of {@link SqlTypeName}s included in this family */ public Collection getTypeNames() { switch (this) { case CHARACTER: return SqlTypeName.CHAR_TYPES; case BINARY: return SqlTypeName.BINARY_TYPES; case NUMERIC: return SqlTypeName.NUMERIC_TYPES; case DECIMAL: return ImmutableList.of(SqlTypeName.DECIMAL); case DATE: return ImmutableList.of(SqlTypeName.DATE); case TIME: return ImmutableList.of(SqlTypeName.TIME, SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE); case TIMESTAMP: return ImmutableList.of(SqlTypeName.TIMESTAMP, SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE); case BOOLEAN: return SqlTypeName.BOOLEAN_TYPES; case INTERVAL_YEAR_MONTH: return SqlTypeName.YEAR_INTERVAL_TYPES; case INTERVAL_DAY_TIME: return SqlTypeName.DAY_INTERVAL_TYPES; case STRING: return SqlTypeName.STRING_TYPES; case APPROXIMATE_NUMERIC: return SqlTypeName.APPROX_TYPES; case EXACT_NUMERIC: return SqlTypeName.EXACT_TYPES; case INTEGER: return SqlTypeName.INT_TYPES; case DATETIME: return SqlTypeName.DATETIME_TYPES; case DATETIME_INTERVAL: return SqlTypeName.INTERVAL_TYPES; case GEO: return ImmutableList.of(SqlTypeName.GEOMETRY); case MULTISET: return ImmutableList.of(SqlTypeName.MULTISET); case ARRAY: return ImmutableList.of(SqlTypeName.ARRAY); case MAP: return ImmutableList.of(SqlTypeName.MAP); case NULL: return ImmutableList.of(SqlTypeName.NULL); case ANY: return SqlTypeName.ALL_TYPES; case CURSOR: return ImmutableList.of(SqlTypeName.CURSOR); case COLUMN_LIST: return ImmutableList.of(SqlTypeName.COLUMN_LIST); default: throw new IllegalArgumentException(); } } /** * @return Default {@link RelDataType} belongs to this family. */ public RelDataType getDefaultConcreteType(RelDataTypeFactory factory) { switch (this) { case CHARACTER: return factory.createSqlType(SqlTypeName.VARCHAR); case BINARY: return factory.createSqlType(SqlTypeName.VARBINARY); case NUMERIC: return SqlTypeUtil.getMaxPrecisionScaleDecimal(factory); case DATE: return factory.createSqlType(SqlTypeName.DATE); case TIME: return factory.createSqlType(SqlTypeName.TIME); case TIMESTAMP: return factory.createSqlType(SqlTypeName.TIMESTAMP); case BOOLEAN: return factory.createSqlType(SqlTypeName.BOOLEAN); case STRING: return factory.createSqlType(SqlTypeName.VARCHAR); case APPROXIMATE_NUMERIC: return factory.createSqlType(SqlTypeName.DOUBLE); case EXACT_NUMERIC: return SqlTypeUtil.getMaxPrecisionScaleDecimal(factory); case INTEGER: return factory.createSqlType(SqlTypeName.BIGINT); case DECIMAL: return factory.createSqlType(SqlTypeName.DECIMAL); case DATETIME: return factory.createSqlType(SqlTypeName.TIMESTAMP); case INTERVAL_DAY_TIME: return factory.createSqlIntervalType( new SqlIntervalQualifier(TimeUnit.DAY, TimeUnit.SECOND, SqlParserPos.ZERO)); case INTERVAL_YEAR_MONTH: return factory.createSqlIntervalType( new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, SqlParserPos.ZERO)); case GEO: return factory.createSqlType(SqlTypeName.GEOMETRY); case MULTISET: return factory.createMultisetType(factory.createSqlType(SqlTypeName.ANY), -1); case ARRAY: return factory.createArrayType(factory.createSqlType(SqlTypeName.ANY), -1); case MAP: return factory.createMapType(factory.createSqlType(SqlTypeName.ANY), factory.createSqlType(SqlTypeName.ANY)); case NULL: return factory.createSqlType(SqlTypeName.NULL); case CURSOR: return factory.createSqlType(SqlTypeName.CURSOR); case COLUMN_LIST: return factory.createSqlType(SqlTypeName.COLUMN_LIST); default: return null; } } public boolean contains(RelDataType type) { return SqlTypeUtil.isOfSameTypeName(getTypeNames(), type); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy