You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2019/05/03 13:41:57 UTC

[flink] branch master updated: [FLINK-12253][table-common] Add a SMALLINT type

This is an automated email from the ASF dual-hosted git repository.

twalthr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 62f88c5  [FLINK-12253][table-common] Add a SMALLINT type
62f88c5 is described below

commit 62f88c5299dc743f7ab77d6cded4d83d86a5ffd2
Author: Timo Walther <tw...@apache.org>
AuthorDate: Tue Apr 30 17:18:00 2019 +0200

    [FLINK-12253][table-common] Add a SMALLINT type
---
 .../table/types/logical/LogicalTypeVisitor.java    |  2 +
 .../flink/table/types/logical/SmallIntType.java    | 91 ++++++++++++++++++++++
 .../apache/flink/table/types/LogicalTypesTest.java | 14 ++++
 3 files changed, 107 insertions(+)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/LogicalTypeVisitor.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/LogicalTypeVisitor.java
index 7fa368e..21fb36f 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/LogicalTypeVisitor.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/LogicalTypeVisitor.java
@@ -43,5 +43,7 @@ public interface LogicalTypeVisitor<R> {
 
 	R visit(TinyIntType tinyIntType);
 
+	R visit(SmallIntType smallIntType);
+
 	R visit(LogicalType other);
 }
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/SmallIntType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/SmallIntType.java
new file mode 100644
index 0000000..c24de82
--- /dev/null
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/SmallIntType.java
@@ -0,0 +1,91 @@
+/*
+ * 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.flink.table.types.logical;
+
+import org.apache.flink.annotation.PublicEvolving;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Logical type of a 2-byte signed integer with values from -32,768 to 32,767.
+ *
+ * <p>The serialized string representation is {@code SMALLINT}.
+ */
+@PublicEvolving
+public final class SmallIntType extends LogicalType {
+
+	private static final String FORMAT = "SMALLINT";
+
+	private static final Set<String> NULL_OUTPUT_CONVERSION = conversionSet(
+		Short.class.getName());
+
+	private static final Set<String> NOT_NULL_INPUT_OUTPUT_CONVERSION = conversionSet(
+		Short.class.getName(),
+		short.class.getName());
+
+	private static final Class<?> DEFAULT_CONVERSION = Short.class;
+
+	public SmallIntType(boolean isNullable) {
+		super(isNullable, LogicalTypeRoot.SMALLINT);
+	}
+
+	public SmallIntType() {
+		this(true);
+	}
+
+	@Override
+	public LogicalType copy(boolean isNullable) {
+		return new SmallIntType(isNullable);
+	}
+
+	@Override
+	public String asSerializableString() {
+		return withNullability(FORMAT);
+	}
+
+	@Override
+	public boolean supportsInputConversion(Class<?> clazz) {
+		return NOT_NULL_INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
+	}
+
+	@Override
+	public boolean supportsOutputConversion(Class<?> clazz) {
+		if (isNullable()) {
+			return NULL_OUTPUT_CONVERSION.contains(clazz.getName());
+		}
+		return NOT_NULL_INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
+	}
+
+	@Override
+	public Class<?> getDefaultConversion() {
+		return DEFAULT_CONVERSION;
+	}
+
+	@Override
+	public List<LogicalType> getChildren() {
+		return Collections.emptyList();
+	}
+
+	@Override
+	public <R> R accept(LogicalTypeVisitor<R> visitor) {
+		return visitor.visit(this);
+	}
+}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
index 7bc90f0..bd61a7d 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
@@ -23,6 +23,7 @@ import org.apache.flink.table.types.logical.BooleanType;
 import org.apache.flink.table.types.logical.CharType;
 import org.apache.flink.table.types.logical.DecimalType;
 import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.SmallIntType;
 import org.apache.flink.table.types.logical.TinyIntType;
 import org.apache.flink.table.types.logical.VarBinaryType;
 import org.apache.flink.table.types.logical.VarCharType;
@@ -135,6 +136,19 @@ public class LogicalTypesTest {
 		);
 	}
 
+	@Test
+	public void testSmallIntType() {
+		testAll(
+			new SmallIntType(),
+			"SMALLINT",
+			"SMALLINT",
+			new Class[]{Short.class, short.class},
+			new Class[]{Short.class},
+			new LogicalType[]{},
+			new SmallIntType(false)
+		);
+	}
+
 	// --------------------------------------------------------------------------------------------
 
 	private static void testAll(