/*
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.dataformat.vector.heap;

import org.apache.flink.table.dataformat.Decimal;
import org.apache.flink.table.dataformat.vector.AbstractColumnVector;
import org.apache.flink.table.types.logical.DecimalType;
import org.apache.flink.table.types.logical.LogicalType;

import java.util.Arrays;

/**
 * Heap vector that nullable shared structure.
 */
public abstract class AbstractHeapVector extends AbstractColumnVector {

	/*
	 * If hasNulls is true, then this array contains true if the value
	 * is null, otherwise false. The array is always allocated, so a batch can be re-used
	 * later and nulls added.
	 */
	protected boolean[] isNull;

	/**
	 * Reusable column for ids of dictionary.
	 */
	protected HeapIntVector dictionaryIds;

	public AbstractHeapVector(int len) {
		isNull = new boolean[len];
	}

	/**
	 * Resets the column to default state.
	 * - fills the isNull array with false.
	 * - sets noNulls to true.
	 */
	@Override
	public void reset() {
		if (!noNulls) {
			Arrays.fill(isNull, false);
		}
		noNulls = true;
	}

	public void setNullAt(int i) {
		isNull[i] = true;
		noNulls = false;
	}

	@Override
	public boolean isNullAt(int i) {
		return !noNulls && isNull[i];
	}

	@Override
	public HeapIntVector reserveDictionaryIds(int capacity) {
		if (dictionaryIds == null) {
			dictionaryIds = new HeapIntVector(capacity);
		} else {
			dictionaryIds.reset();
		}
		return dictionaryIds;
	}

	/**
	 * Returns the underlying integer column for ids of dictionary.
	 */
	public HeapIntVector getDictionaryIds() {
		return dictionaryIds;
	}

	public static AbstractHeapVector[] allocateHeapVectors(LogicalType[] fieldTypes, int maxRows) {
		AbstractHeapVector[] columns = new AbstractHeapVector[fieldTypes.length];
		for (int i = 0; i < fieldTypes.length; i++) {
			columns[i] = createHeapColumn(fieldTypes[i], maxRows);
		}
		return columns;
	}

	public static AbstractHeapVector createHeapColumn(LogicalType fieldType, int maxRows) {
		switch (fieldType.getTypeRoot()) {
			case BOOLEAN:
				return new HeapBooleanVector(maxRows);
			case TINYINT:
				return new HeapByteVector(maxRows);
			case DOUBLE:
				return new HeapDoubleVector(maxRows);
			case FLOAT:
				return new HeapFloatVector(maxRows);
			case INTEGER:
			case DATE:
			case TIME_WITHOUT_TIME_ZONE:
				return new HeapIntVector(maxRows);
			case BIGINT:
			case TIMESTAMP_WITHOUT_TIME_ZONE:
			case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
				return new HeapLongVector(maxRows);
			case DECIMAL:
				DecimalType decimalType = (DecimalType) fieldType;
				if (Decimal.is32BitDecimal(decimalType.getPrecision())) {
					return new HeapIntVector(maxRows);
				} else if (Decimal.is64BitDecimal(decimalType.getPrecision())) {
					return new HeapLongVector(maxRows);
				} else {
					return new HeapBytesVector(maxRows);
				}
			case SMALLINT:
				return new HeapShortVector(maxRows);
			case CHAR:
			case VARCHAR:
			case BINARY:
			case VARBINARY:
				return new HeapBytesVector(maxRows);
			default:
				throw new UnsupportedOperationException(fieldType  + " is not supported now.");
		}
	}
}

@@ -905,199 +905,35 @@
 mat.
-Decimal;%0Aimport org.apache.flink.table.dataformat.vector.AbstractColumnVector;%0Aimport org.apache.flink.table.types.logical.DecimalType;%0Aimport org.apache.flink.table.types.logical.LogicalType
+vector.AbstractColumnVector
 ;%0A%0Ai
@@ -2187,24 +2187,24 @@
 naryIds() %7B%0A
+
 %09%09return dic
@@ -2221,1519 +2221,7 @@
 ;%0A%09%7D
-%0A%0A%09public static AbstractHeapVector%5B%5D allocateHeapVectors(LogicalType%5B%5D fieldTypes, int maxRows) %7B%0A%09%09AbstractHeapVector%5B%5D columns = new AbstractHeapVector%5BfieldTypes.length%5D;%0A%09%09for (int i = 0; i %3C fieldTypes.length; i++) %7B%0A%09%09%09columns%5Bi%5D = createHeapColumn(fieldTypes%5Bi%5D, maxRows);%0A%09%09%7D%0A%09%09return columns;%0A%09%7D%0A%0A%09public static AbstractHeapVector createHeapColumn(LogicalType fieldType, int maxRows) %7B%0A%09%09switch (fieldType.getTypeRoot()) %7B%0A%09%09%09case BOOLEAN:%0A%09%09%09%09return new HeapBooleanVector(maxRows);%0A%09%09%09case TINYINT:%0A%09%09%09%09return new HeapByteVector(maxRows);%0A%09%09%09case DOUBLE:%0A%09%09%09%09return new HeapDoubleVector(maxRows);%0A%09%09%09case FLOAT:%0A%09%09%09%09return new HeapFloatVector(maxRows);%0A%09%09%09case INTEGER:%0A%09%09%09case DATE:%0A%09%09%09case TIME_WITHOUT_TIME_ZONE:%0A%09%09%09%09return new HeapIntVector(maxRows);%0A%09%09%09case BIGINT:%0A%09%09%09case TIMESTAMP_WITHOUT_TIME_ZONE:%0A%09%09%09case TIMESTAMP_WITH_LOCAL_TIME_ZONE:%0A%09%09%09%09return new HeapLongVector(maxRows);%0A%09%09%09case DECIMAL:%0A%09%09%09%09DecimalType decimalType = (DecimalType) fieldType;%0A%09%09%09%09if (Decimal.is32BitDecimal(decimalType.getPrecision())) %7B%0A%09%09%09%09%09return new HeapIntVector(maxRows);%0A%09%09%09%09%7D else if (Decimal.is64BitDecimal(decimalType.getPrecision())) %7B%0A%09%09%09%09%09return new HeapLongVector(maxRows);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09return new HeapBytesVector(maxRows);%0A%09%09%09%09%7D%0A%09%09%09case SMALLINT:%0A%09%09%09%09return new HeapShortVector(maxRows);%0A%09%09%09case CHAR:%0A%09%09%09case VARCHAR:%0A%09%09%09case BINARY:%0A%09%09%09case VARBINARY:%0A%09%09%09%09return new HeapBytesVector(maxRows);%0A%09%09%09default:%0A%09%09%09%09throw new UnsupportedOperationException(fieldType  + %22 is not supported now.%22);%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Remove useless methods in AbstractHeapVector