From 253c1c3541b937026021b2bed4e720849d2713ae Mon Sep 17 00:00:00 2001 From: Nicolas Adment <39568358+nadment@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:35:05 +0100 Subject: [PATCH] The ANY type name is in the same family as any other type name --- .../apache/hop/expression/IExpression.java | 2 +- .../org/apache/hop/expression/type/Type.java | 2 +- .../apache/hop/expression/type/TypeName.java | 644 +++++++++--------- .../org/apache/hop/expression/TypeTest.java | 106 ++- 4 files changed, 364 insertions(+), 390 deletions(-) diff --git a/src/main/java/org/apache/hop/expression/IExpression.java b/src/main/java/org/apache/hop/expression/IExpression.java index b3df8af1..af41da79 100644 --- a/src/main/java/org/apache/hop/expression/IExpression.java +++ b/src/main/java/org/apache/hop/expression/IExpression.java @@ -33,7 +33,7 @@ public interface IExpression { */ public Kind getKind(); - public default boolean is(Kind kind) { + public default boolean is(final Kind kind) { return getKind() == kind; } diff --git a/src/main/java/org/apache/hop/expression/type/Type.java b/src/main/java/org/apache/hop/expression/type/Type.java index 0d5bfa82..f5fee0c8 100644 --- a/src/main/java/org/apache/hop/expression/type/Type.java +++ b/src/main/java/org/apache/hop/expression/type/Type.java @@ -193,7 +193,7 @@ public T convert(final Object value, Class clazz) throws ConversionExcept ErrorCode.UNSUPPORTED_COERCION, value, TypeName.fromValue(value), - TypeName.fromJavaClass(clazz)); + TypeName.fromClass(clazz)); } /** diff --git a/src/main/java/org/apache/hop/expression/type/TypeName.java b/src/main/java/org/apache/hop/expression/type/TypeName.java index bee92cc8..b15c255c 100644 --- a/src/main/java/org/apache/hop/expression/type/TypeName.java +++ b/src/main/java/org/apache/hop/expression/type/TypeName.java @@ -1,320 +1,324 @@ -/* - * 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.hop.expression.type; - -import com.fasterxml.jackson.databind.JsonNode; -import java.math.BigDecimal; -import java.net.InetAddress; -import java.time.ZonedDateTime; -import java.util.Set; -import org.apache.hop.expression.Array; -import org.apache.hop.expression.Interval; -import org.apache.hop.expression.TimeUnit; - -/** - * Enumeration of the data type identifier which can be used to construct an expression. - * - *

The order of enum declaration is important to be usable with compareTo method. - * - *

If values need to be converted to match the other operands data type, the value with the lower - * order is converted to the value with the higher order. - */ -public enum TypeName { - - /** The null value. It has its own special type. */ - UNKNOWN(TypeFamily.UNKNOWN, false, false, -1, -1, -1, -1, Void.class), - - ANY(TypeFamily.ANY, false, false, -1, -1, -1, -1, Object.class), - - /** Unlimited length text */ - STRING(TypeFamily.STRING, true, false, 16_777_216, 1, 0, 0, String.class), - - /** Boolean (true or false) */ - BOOLEAN(TypeFamily.BOOLEAN, false, false, 1, 0, 0, 0, Boolean.class), - - /** Signed integer (64-bit) */ - INTEGER(TypeFamily.NUMERIC, true, false, 19, 1, 0, 0, Long.class), - - /** Unlimited precision number */ - NUMBER(TypeFamily.NUMERIC, true, true, 38, 1, 37, 0, BigDecimal.class), - - /** A interval type TODO: add precision for nanoseconds */ - INTERVAL(TypeFamily.INTERVAL, false, false, -1, -1, -1, -1, Interval.class), - - /** Date-time value with nanosecond precision and time zone TODO: add precision for nanoseconds */ - DATE(TypeFamily.TEMPORAL, false, false, -1, -1, -1, -1, ZonedDateTime.class), - - /** A Json type */ - JSON(TypeFamily.JSON, false, false, -1, -1, -1, -1, JsonNode.class), - - /** A INET type */ - INET(TypeFamily.NETWORK, false, false, -1, -1, -1, -1, InetAddress.class), - - /** A binary type can be images, sounds, videos, and other types of binary data */ - BINARY(TypeFamily.BINARY, true, false, 16_777_216, 1, 0, 0, byte[].class), - - /** A Array type */ - ARRAY(TypeFamily.ARRAY, false, false, -1, -1, 0, 0, Array.class), - - TIMEUNIT(TypeFamily.SYMBOL, false, false, -1, -1, -1, -1, TimeUnit.class); - - protected static final Set STRING_TYPES = Set.of(STRING); - protected static final Set BINARY_TYPES = Set.of(BINARY); - protected static final Set BOOLEAN_TYPES = Set.of(BOOLEAN); - protected static final Set NUMERIC_TYPES = Set.of(INTEGER, NUMBER); - protected static final Set TEMPORAL_TYPES = Set.of(DATE); - protected static final Set JSON_TYPES = Set.of(JSON); - protected static final Set INTERVAL_TYPES = Set.of(INTERVAL); - - protected static final Set PRIMARY_TYPES = - Set.of(STRING, BOOLEAN, INTEGER, NUMBER, DATE, INTERVAL, BINARY, JSON); - - /** If the precision parameter is supported. */ - private boolean supportsPrecision; - - /** If the scale parameter is supported. */ - private boolean supportsScale; - - /** The minimum supported precision. */ - private int minPrecision; - - /** The maximum supported precision. */ - private int maxPrecision; - - /** The lowest possible scale. */ - private int minScale; - - /** The highest possible scale. */ - private int maxScale; - - private final TypeFamily family; - - private final Class javaClass; - - public static final Set ALL_NAMES = - Set.of( - "Binary", "Boolean", "Date", "Integer", "Number", "Json", "String", "Interval", "Inet"); - - private TypeName( - TypeFamily family, - boolean supportsPrecision, - boolean supportsScale, - int maxPrecision, - int minPrecision, - int maxScale, - int minScale, - Class javaClass) { - this.family = family; - this.supportsPrecision = supportsPrecision; - this.supportsScale = supportsScale; - this.maxPrecision = maxPrecision; - this.minPrecision = minPrecision; - this.maxScale = maxScale; - this.minScale = minScale; - this.javaClass = javaClass; - } - - public Class getJavaClass() { - return javaClass; - } - - /** Gets the {@link TypeFamily} containing this {@link TypeName}. */ - public TypeFamily getFamily() { - return family; - } - - /** Returns whether type are in same type family. */ - public boolean isFamily(TypeFamily family) { - return this.family == family; - } - - /** - * Returns whether this {@link TypeName} support explicit cast to the specified {@link TypeName}. - */ - public boolean isCastable(final TypeName name) { - if (name == null) return false; - if (ANY == this || name == ANY || this.equals(name)) return true; - - switch (this) { - case BOOLEAN: - return name.is(INTEGER, NUMBER, BINARY, STRING); - case STRING: - return name.is(BOOLEAN, INTEGER, NUMBER, DATE, BINARY, JSON, INET); - case DATE: - return name.is(INTEGER, NUMBER, STRING); - case INTEGER: - return name.is(NUMBER, BOOLEAN, BINARY, STRING, DATE); - case NUMBER: - return name.is(INTEGER, BOOLEAN, BINARY, STRING, DATE); - case BINARY: - return name.is(STRING); - case JSON: - return name.is(STRING); - case UNKNOWN, ANY: - return true; - case INTERVAL: - case INET: - case TIMEUNIT: - default: - return false; - } - } - - /** - * Returns whether this {@link TypeName} support implicit coercion to the specified {@link - * TypeName}. Implicit coercions is generally only possible when the cast cannot fail. - */ - public boolean isCoercible(final TypeName name) { - if (name == null) return false; - if (ANY == this || name == ANY || this.equals(name)) return true; - switch (this) { - case BOOLEAN: - return name.is(INTEGER, NUMBER, STRING); - case DATE: - return name.is(STRING); - case INTEGER: - return name.is(NUMBER, BOOLEAN, STRING); - case NUMBER: - // TODO: NUMBER to INTEGER can overflow, not sure it's a good choice to coerce - return name.is(INTEGER, BOOLEAN, STRING); - case BINARY: - return name.is(STRING); - case STRING: - return name.is(BINARY); - case JSON: - return name.is(STRING); - case INTERVAL: - return name.is(STRING); - case INET: - return name.is(STRING); - case UNKNOWN, ANY: - return true; - case ARRAY: - default: - return false; - } - } - - public boolean supportsPrecision() { - return this.supportsPrecision; - } - - public boolean supportsScale() { - return this.supportsScale; - } - - /** - * Returns the minimum precision (or length) allowed for this type, or -1 if precision/length are - * not applicable for this type. - * - * @return Minimum allowed precision - */ - public int getMinPrecision() { - return minPrecision; - } - - /** - * Returns the maximum precision (or length) allowed for this type, or -1 if precision/length are - * not applicable for this type. - * - * @return Maximum allowed precision - */ - public int getMaxPrecision() { - return maxPrecision; - } - - public int getMaxScale() { - return maxScale; - } - - public int getMinScale() { - return minScale; - } - - public int getDefaultScale() { - switch (this) { - case NUMBER: - return 9; - case BOOLEAN: - return 0; - default: - return -1; - } - } - - /** - * Returns a {@link TypeName} with a given name (ignore case). - * - * @param name The name of the data name - * @return data name, or null if not valid - */ - public static TypeName of(final String name) { - for (TypeName type : TypeName.values()) { - if (type.name().equalsIgnoreCase(name)) { - return type; - } - } - return null; - } - - /** - * Search a data type identifier from a java class. - * - * @return The {@link TypeName} or 'UNKNOWN' if not found - */ - public static TypeName fromJavaClass(final Class clazz) { - if (clazz == null) return UNKNOWN; - - for (TypeName id : values()) { - - // Ignore ANY - if (id.equals(ANY)) continue; - - if (id.getJavaClass().isAssignableFrom(clazz)) { - return id; - } - } - return UNKNOWN; - } - - /** - * Search a data type identifier from a value. - * - * @return The type id or 'UNKNOWN' if not found - */ - public static TypeName fromValue(final Object value) { - if (value == null) return UNKNOWN; - - if (value instanceof Integer) { - return INTEGER; - } - if (value instanceof Double) { - return NUMBER; - } - - return fromJavaClass(value.getClass()); - } - - /** Returns whether type are in same type. */ - public boolean is(final TypeName... names) { - if (names == null) return false; - for (TypeName name : names) { - if (ANY == this || name == ANY || this.equals(name)) return true; - } - return false; - } -} +/* + * 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.hop.expression.type; + +import com.fasterxml.jackson.databind.JsonNode; +import java.math.BigDecimal; +import java.net.InetAddress; +import java.time.ZonedDateTime; +import java.util.Set; +import org.apache.hop.expression.Array; +import org.apache.hop.expression.Interval; +import org.apache.hop.expression.TimeUnit; + +/** + * Enumeration of the data type identifier which can be used to construct an expression. + * + *

The order of enum declaration is important to be usable with compareTo method. + * + *

If values need to be converted to match the other operands data type, the value with the lower + * order is converted to the value with the higher order. + */ +public enum TypeName { + + /** The null value. It has its own special type. */ + UNKNOWN(TypeFamily.UNKNOWN, false, false, -1, -1, -1, -1, Void.class), + + ANY(TypeFamily.ANY, false, false, -1, -1, -1, -1, Object.class), + + /** Unlimited length text */ + STRING(TypeFamily.STRING, true, false, 16_777_216, 1, 0, 0, String.class), + + /** Boolean (true or false) */ + BOOLEAN(TypeFamily.BOOLEAN, false, false, 1, 0, 0, 0, Boolean.class), + + /** Signed integer (64-bit) */ + INTEGER(TypeFamily.NUMERIC, true, false, 19, 1, 0, 0, Long.class), + + /** Unlimited precision number */ + NUMBER(TypeFamily.NUMERIC, true, true, 38, 1, 37, 0, BigDecimal.class), + + /** A interval type TODO: add precision for nanoseconds */ + INTERVAL(TypeFamily.INTERVAL, false, false, -1, -1, -1, -1, Interval.class), + + /** Date-time value with nanosecond precision and time zone TODO: add precision for nanoseconds */ + DATE(TypeFamily.TEMPORAL, false, false, -1, -1, -1, -1, ZonedDateTime.class), + + /** A Json type */ + JSON(TypeFamily.JSON, false, false, -1, -1, -1, -1, JsonNode.class), + + /** A INET type */ + INET(TypeFamily.NETWORK, false, false, -1, -1, -1, -1, InetAddress.class), + + /** A binary type can be images, sounds, videos, and other types of binary data */ + BINARY(TypeFamily.BINARY, true, false, 16_777_216, 1, 0, 0, byte[].class), + + /** A Array type */ + ARRAY(TypeFamily.ARRAY, false, false, -1, -1, 0, 0, Array.class), + + TIMEUNIT(TypeFamily.SYMBOL, false, false, -1, -1, -1, -1, TimeUnit.class); + + protected static final Set STRING_TYPES = Set.of(STRING); + protected static final Set BINARY_TYPES = Set.of(BINARY); + protected static final Set BOOLEAN_TYPES = Set.of(BOOLEAN); + protected static final Set NUMERIC_TYPES = Set.of(INTEGER, NUMBER); + protected static final Set TEMPORAL_TYPES = Set.of(DATE); + protected static final Set JSON_TYPES = Set.of(JSON); + protected static final Set INTERVAL_TYPES = Set.of(INTERVAL); + + protected static final Set PRIMARY_TYPES = + Set.of(STRING, BOOLEAN, INTEGER, NUMBER, DATE, INTERVAL, BINARY, JSON); + + /** If the precision parameter is supported. */ + private boolean supportsPrecision; + + /** If the scale parameter is supported. */ + private boolean supportsScale; + + /** The minimum supported precision. */ + private int minPrecision; + + /** The maximum supported precision. */ + private int maxPrecision; + + /** The lowest possible scale. */ + private int minScale; + + /** The highest possible scale. */ + private int maxScale; + + private final TypeFamily family; + + private final Class javaClass; + + public static final Set ALL_NAMES = + Set.of( + "Binary", "Boolean", "Date", "Integer", "Number", "Json", "String", "Interval", "Inet"); + + private TypeName( + TypeFamily family, + boolean supportsPrecision, + boolean supportsScale, + int maxPrecision, + int minPrecision, + int maxScale, + int minScale, + Class javaClass) { + this.family = family; + this.supportsPrecision = supportsPrecision; + this.supportsScale = supportsScale; + this.maxPrecision = maxPrecision; + this.minPrecision = minPrecision; + this.maxScale = maxScale; + this.minScale = minScale; + this.javaClass = javaClass; + } + + public Class getJavaClass() { + return javaClass; + } + + /** Gets the {@link TypeFamily} containing this {@link TypeName}. */ + public TypeFamily getFamily() { + return family; + } + + /** + * Returns whether {@link TypeName} are in same type family. The ANY {@link TypeName} is in the + * same family as any other {@link TypeName} type. + */ + public boolean isFamily(TypeFamily other) { + return this.family == TypeFamily.ANY || this.family == other; + } + + /** + * Returns whether this {@link TypeName} support explicit cast to the specified {@link TypeName}. + */ + public boolean isCastable(final TypeName name) { + if (name == null) return false; + if (name == this) return true; + + switch (this) { + case BOOLEAN: + return name.is(INTEGER, NUMBER, BINARY, STRING); + case STRING: + return name.is(BOOLEAN, INTEGER, NUMBER, DATE, BINARY, JSON, INET); + case DATE: + return name.is(INTEGER, NUMBER, STRING); + case INTEGER: + return name.is(NUMBER, BOOLEAN, BINARY, STRING, DATE); + case NUMBER: + return name.is(INTEGER, BOOLEAN, BINARY, STRING, DATE); + case BINARY: + return name.is(STRING); + case JSON: + return name.is(STRING); + case INET: + return name.is(STRING); + case UNKNOWN, ANY: + return true; + case INTERVAL: + case TIMEUNIT: + default: + return false; + } + } + + /** + * Returns whether this {@link TypeName} support implicit coercion to the specified {@link + * TypeName}. Implicit coercions is generally only possible when the cast cannot fail. + */ + public boolean isCoercible(final TypeName name) { + if (name == null) return false; + if (ANY == this || name == ANY || this.equals(name)) return true; + switch (this) { + case BOOLEAN: + return name.is(INTEGER, NUMBER, STRING); + case DATE: + return name.is(STRING); + case INTEGER: + return name.is(NUMBER, BOOLEAN, STRING); + case NUMBER: + // TODO: NUMBER to INTEGER can overflow, not sure it's a good choice to coerce + return name.is(INTEGER, BOOLEAN, STRING); + case BINARY: + return name.is(STRING); + case STRING: + return name.is(BINARY); + case JSON: + return name.is(STRING); + case INTERVAL: + return name.is(STRING); + case INET: + return name.is(STRING); + case UNKNOWN, ANY: + return true; + case ARRAY: + default: + return false; + } + } + + public boolean supportsPrecision() { + return this.supportsPrecision; + } + + public boolean supportsScale() { + return this.supportsScale; + } + + /** + * Returns the minimum precision (or length) allowed for this type, or -1 if precision/length are + * not applicable for this type. + * + * @return Minimum allowed precision + */ + public int getMinPrecision() { + return minPrecision; + } + + /** + * Returns the maximum precision (or length) allowed for this type, or -1 if precision/length are + * not applicable for this type. + * + * @return Maximum allowed precision + */ + public int getMaxPrecision() { + return maxPrecision; + } + + public int getMaxScale() { + return maxScale; + } + + public int getMinScale() { + return minScale; + } + + public int getDefaultScale() { + switch (this) { + case NUMBER: + return 9; + case BOOLEAN: + return 0; + default: + return -1; + } + } + + /** + * Returns a {@link TypeName} with a given name (ignore case). + * + * @param name The name of the data name + * @return data name, or null if not valid + */ + public static TypeName of(final String name) { + for (TypeName type : TypeName.values()) { + if (type.name().equalsIgnoreCase(name)) { + return type; + } + } + return null; + } + + /** + * Search a data type identifier from a java class. + * + * @return The {@link TypeName} or 'UNKNOWN' if not found + */ + public static TypeName fromClass(final Class clazz) { + if (clazz == null) return UNKNOWN; + + for (TypeName id : values()) { + + // Ignore ANY + if (id.equals(ANY)) continue; + + if (id.getJavaClass().isAssignableFrom(clazz)) { + return id; + } + } + return UNKNOWN; + } + + /** + * Search a data type identifier from a value. + * + * @return The type id or 'UNKNOWN' if not found + */ + public static TypeName fromValue(final Object value) { + if (value == null) return UNKNOWN; + + if (value instanceof Integer) { + return INTEGER; + } + if (value instanceof Double) { + return NUMBER; + } + + return fromClass(value.getClass()); + } + + /** Returns whether type are in same type. */ + public boolean is(final TypeName... names) { + if (names == null) return false; + for (TypeName name : names) { + if (ANY == this || name == ANY || this.equals(name)) return true; + } + return false; + } +} diff --git a/src/test/java/org/apache/hop/expression/TypeTest.java b/src/test/java/org/apache/hop/expression/TypeTest.java index d9c021a9..5de32d9a 100644 --- a/src/test/java/org/apache/hop/expression/TypeTest.java +++ b/src/test/java/org/apache/hop/expression/TypeTest.java @@ -39,6 +39,7 @@ import org.apache.hop.expression.type.NumberType; import org.apache.hop.expression.type.StringType; import org.apache.hop.expression.type.Type; +import org.apache.hop.expression.type.TypeFamily; import org.apache.hop.expression.type.TypeName; import org.apache.hop.expression.type.Types; import org.apache.hop.expression.type.UnknownType; @@ -138,25 +139,25 @@ void typeNameOf() throws Exception { } @Test - void typeNameFromJavaClass() throws Exception { - assertEquals(TypeName.UNKNOWN, TypeName.fromJavaClass(null)); - assertEquals(TypeName.UNKNOWN, TypeName.fromJavaClass(Void.class)); - assertEquals(TypeName.UNKNOWN, TypeName.fromJavaClass(Float.class)); - assertEquals(TypeName.UNKNOWN, TypeName.fromJavaClass(Type.class)); - assertEquals(TypeName.TIMEUNIT, TypeName.fromJavaClass(TimeUnit.class)); - assertEquals(TypeName.BOOLEAN, TypeName.fromJavaClass(Boolean.class)); - assertEquals(TypeName.STRING, TypeName.fromJavaClass(String.class)); - assertEquals(TypeName.DATE, TypeName.fromJavaClass(ZonedDateTime.class)); - assertEquals(TypeName.NUMBER, TypeName.fromJavaClass(BigDecimal.class)); - assertEquals(TypeName.BINARY, TypeName.fromJavaClass(byte[].class)); - assertEquals(TypeName.JSON, TypeName.fromJavaClass(JsonNode.class)); - assertEquals(TypeName.INET, TypeName.fromJavaClass(InetAddress.class)); - assertEquals(TypeName.INTEGER, TypeName.fromJavaClass(Long.class)); - assertEquals(TypeName.ARRAY, TypeName.fromJavaClass(Array.class)); + void typeNameFromClass() throws Exception { + assertEquals(TypeName.UNKNOWN, TypeName.fromClass(null)); + assertEquals(TypeName.UNKNOWN, TypeName.fromClass(Void.class)); + assertEquals(TypeName.UNKNOWN, TypeName.fromClass(Float.class)); + assertEquals(TypeName.UNKNOWN, TypeName.fromClass(Type.class)); + assertEquals(TypeName.TIMEUNIT, TypeName.fromClass(TimeUnit.class)); + assertEquals(TypeName.BOOLEAN, TypeName.fromClass(Boolean.class)); + assertEquals(TypeName.STRING, TypeName.fromClass(String.class)); + assertEquals(TypeName.DATE, TypeName.fromClass(ZonedDateTime.class)); + assertEquals(TypeName.NUMBER, TypeName.fromClass(BigDecimal.class)); + assertEquals(TypeName.BINARY, TypeName.fromClass(byte[].class)); + assertEquals(TypeName.JSON, TypeName.fromClass(JsonNode.class)); + assertEquals(TypeName.INET, TypeName.fromClass(InetAddress.class)); + assertEquals(TypeName.INTEGER, TypeName.fromClass(Long.class)); + assertEquals(TypeName.ARRAY, TypeName.fromClass(Array.class)); } @Test - void typeIdFromValue() throws Exception { + void typeNameFromValue() throws Exception { assertEquals(TypeName.UNKNOWN, TypeName.fromValue(null)); assertEquals(TypeName.UNKNOWN, TypeName.fromValue(new Random())); assertEquals(TypeName.BOOLEAN, TypeName.fromValue(true)); @@ -173,58 +174,27 @@ void typeIdFromValue() throws Exception { assertEquals(TypeName.JSON, TypeName.fromValue(JsonType.convert("{\"name\":\"Smith\"}"))); } - // @Test - // void isFamily() throws Exception { - // assertTrue(TypeId.ANY.isFamily(TypeFamily.ANY)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.BINARY)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.BOOLEAN)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.NUMERIC)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.TEMPORAL)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.STRING)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.INTERVAL)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.JSON)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.INET)); - // assertTrue(TypeId.ANY.isFamily(TypeFamily.ARRAY)); - // - // assertTrue(TypeId.INTEGER.isFamily(TypeFamily.NUMERIC)); - // assertTrue(TypeId.NUMBER.isFamily(TypeFamily.NUMERIC)); - // assertTrue(TypeId.BOOLEAN.isFamily(TypeFamily.BOOLEAN)); - // assertTrue(TypeId.STRING.isFamily(TypeFamily.STRING)); - // assertTrue(TypeId.DATE.isFamily(TypeFamily.TEMPORAL)); - // assertTrue(TypeId.INTERVAL.isFamily(TypeFamily.INTERVAL)); - // assertTrue(TypeId.BINARY.isFamily(TypeFamily.BINARY)); - // assertTrue(TypeId.INET.isFamily(TypeFamily.INET)); - // - // assertTrue(Types.ANY.isFamily(TypeFamily.BINARY)); - // assertTrue(Types.ANY.isFamily(TypeFamily.BOOLEAN)); - // assertTrue(Types.ANY.isFamily(TypeFamily.NUMERIC)); - // assertTrue(Types.ANY.isFamily(TypeFamily.TEMPORAL)); - // assertTrue(Types.ANY.isFamily(TypeFamily.STRING)); - // assertTrue(Types.ANY.isFamily(TypeFamily.JSON)); - // assertTrue(Types.ANY.isFamily(TypeFamily.ANY)); - // - // assertTrue(Types.BINARY.isFamily(TypeFamily.ANY)); - // assertTrue(Types.BINARY.isFamily(TypeFamily.BINARY)); - // assertFalse(Types.BINARY.isFamily(TypeFamily.NUMERIC)); - // assertTrue(Types.BINARY.isFamily(TypeFamily.ANY)); - // assertFalse(Types.BINARY.isFamily(TypeFamily.SYMBOL)); - // assertTrue(Types.BINARY.isFamily(TypeFamily.BINARY)); - // - // assertTrue(Types.BOOLEAN.isFamily(TypeFamily.BOOLEAN)); - // assertTrue(Types.DATE.isFamily(TypeFamily.TEMPORAL)); - // assertTrue(Types.INTEGER.isFamily(TypeFamily.NUMERIC)); - // assertTrue(Types.NUMBER.isFamily(TypeFamily.NUMERIC)); - // assertTrue(Types.STRING.isFamily(TypeFamily.STRING)); - // - // assertEquals(TypeFamily.BINARY, Types.BINARY.getFamily()); - // assertEquals(TypeFamily.BOOLEAN, Types.BOOLEAN.getFamily()); - // assertEquals(TypeFamily.TEMPORAL, Types.DATE.getFamily()); - // assertEquals(TypeFamily.JSON, Types.JSON.getFamily()); - // assertEquals(TypeFamily.NUMERIC, Types.INTEGER.getFamily()); - // assertEquals(TypeFamily.NUMERIC, Types.NUMBER.getFamily()); - // assertEquals(TypeFamily.STRING, Types.STRING.getFamily()); - // assertEquals(TypeFamily.INTERVAL, Types.INTERVAL.getFamily()); - // } + @Test + void isFamily() throws Exception { + assertTrue(TypeName.ANY.isFamily(TypeFamily.ANY)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.BINARY)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.BOOLEAN)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.NUMERIC)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.TEMPORAL)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.STRING)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.INTERVAL)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.JSON)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.NETWORK)); + assertTrue(TypeName.ANY.isFamily(TypeFamily.ARRAY)); + assertTrue(TypeName.INTEGER.isFamily(TypeFamily.NUMERIC)); + assertTrue(TypeName.NUMBER.isFamily(TypeFamily.NUMERIC)); + assertTrue(TypeName.BOOLEAN.isFamily(TypeFamily.BOOLEAN)); + assertTrue(TypeName.STRING.isFamily(TypeFamily.STRING)); + assertTrue(TypeName.DATE.isFamily(TypeFamily.TEMPORAL)); + assertTrue(TypeName.INTERVAL.isFamily(TypeFamily.INTERVAL)); + assertTrue(TypeName.BINARY.isFamily(TypeFamily.BINARY)); + assertTrue(TypeName.INET.isFamily(TypeFamily.NETWORK)); + } @Test void javaClass() throws Exception {