diff --git a/core/src/main/java/org/apache/calcite/avatica/SqlType.java b/core/src/main/java/org/apache/calcite/avatica/SqlType.java index 840e218e4..2ede01121 100644 --- a/core/src/main/java/org/apache/calcite/avatica/SqlType.java +++ b/core/src/main/java/org/apache/calcite/avatica/SqlType.java @@ -378,7 +378,12 @@ public enum SqlType { public static SqlType valueOf(int type) { final SqlType sqlType = BY_ID.get(type); if (sqlType == null) { - throw new IllegalArgumentException("Unknown SQL type " + type); + // In most cases the ANY type will allow non-standard types to be displayable in + // the query requests. However, I think we should add the ability to specify + // a non-standard type factory that can be referenced here to see if the type is supported. + // For now, we will just return ANY to unblock users of databases + // that support non-standard types. + return ANY; } return sqlType; } diff --git a/core/src/test/java/org/apache/calcite/avatica/SqlTypeTest.java b/core/src/test/java/org/apache/calcite/avatica/SqlTypeTest.java new file mode 100644 index 000000000..397af8490 --- /dev/null +++ b/core/src/test/java/org/apache/calcite/avatica/SqlTypeTest.java @@ -0,0 +1,63 @@ +/* + * 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.avatica; + +import org.junit.Test; + +import java.sql.Types; +import java.util.*; + +import static org.junit.Assert.assertEquals; + +/** + * Test class for {@link SqlType}. + */ +public class SqlTypeTest { + + @Test public void ensureAnyIsGivenForNonStandardSqlTypes() { + // Arrange + // Oracle TIMESTAMP WITH TIME ZONE + int timestampWithTimeZoneTypeValue = -101; + // SQL server DateTimeOffset + int dateTimeOffset = -155; + + // Act + SqlType tsSqlType = SqlType.valueOf(timestampWithTimeZoneTypeValue); + SqlType dtoSqlType = SqlType.valueOf(dateTimeOffset); + + // Assert + assertEquals(SqlType.ANY, tsSqlType); + assertEquals(SqlType.ANY, dtoSqlType); + } + + @Test public void ensureStandardSqlTypesAreFound() { + // Arrange + Map typeMap = new HashMap<>(); + + for (SqlType sqlType : SqlType.values()) { + typeMap.put(sqlType.id, sqlType); + } + + Set typeValues = typeMap.keySet(); + + // Act and Assert + for (Integer typeValue : typeValues) { + assertEquals(typeMap.get(typeValue), SqlType.valueOf(typeValue)); + } + } +}