<commit_before>/*
 * 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.runtime.typeutils;

import org.apache.flink.annotation.Internal;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.common.typeutils.base.BooleanSerializer;
import org.apache.flink.api.common.typeutils.base.ByteSerializer;
import org.apache.flink.api.common.typeutils.base.DoubleSerializer;
import org.apache.flink.api.common.typeutils.base.FloatSerializer;
import org.apache.flink.api.common.typeutils.base.IntSerializer;
import org.apache.flink.api.common.typeutils.base.LongSerializer;
import org.apache.flink.api.common.typeutils.base.ShortSerializer;
import org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArraySerializer;
import org.apache.flink.table.types.logical.ArrayType;
import org.apache.flink.table.types.logical.DistinctType;
import org.apache.flink.table.types.logical.IntType;
import org.apache.flink.table.types.logical.LogicalType;
import org.apache.flink.table.types.logical.MapType;
import org.apache.flink.table.types.logical.MultisetType;
import org.apache.flink.table.types.logical.RawType;
import org.apache.flink.table.types.logical.TypeInformationRawType;

import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getPrecision;
import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getScale;

/**
 * {@link TypeSerializer} of {@link LogicalType} for internal data structures.
 */
@Internal
public final class InternalSerializers {

	/**
	 * Creates a {@link TypeSerializer} for internal data structures of the given {@link LogicalType}.
	 */
	@SuppressWarnings("unchecked")
	public static <T> TypeSerializer<T> create(LogicalType type) {
		return (TypeSerializer<T>) createInternal(type);
	}

	private static TypeSerializer<?> createInternal(LogicalType type) {
		// ordered by type root definition
		switch (type.getTypeRoot()) {
			case CHAR:
			case VARCHAR:
				return StringDataSerializer.INSTANCE;
			case BOOLEAN:
				return BooleanSerializer.INSTANCE;
			case BINARY:
			case VARBINARY:
				return BytePrimitiveArraySerializer.INSTANCE;
			case DECIMAL:
				return new DecimalDataSerializer(getPrecision(type), getScale(type));
			case TINYINT:
				return ByteSerializer.INSTANCE;
			case SMALLINT:
				return ShortSerializer.INSTANCE;
			case INTEGER:
			case DATE:
			case TIME_WITHOUT_TIME_ZONE:
			case INTERVAL_YEAR_MONTH:
				return IntSerializer.INSTANCE;
			case BIGINT:<commit_msg>[hotfix][table-runtime-blink] Get RowDataSerializer from InternalSerializers<commit_after>/*
 * 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.runtime.typeutils;

import org.apache.flink.annotation.Internal;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.common.typeutils.base.BooleanSerializer;
import org.apache.flink.api.common.typeutils.base.ByteSerializer;
import org.apache.flink.api.common.typeutils.base.DoubleSerializer;
import org.apache.flink.api.common.typeutils.base.FloatSerializer;
import org.apache.flink.api.common.typeutils.base.IntSerializer;
import org.apache.flink.api.common.typeutils.base.LongSerializer;
import org.apache.flink.api.common.typeutils.base.ShortSerializer;
import org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArraySerializer;
import org.apache.flink.table.types.logical.ArrayType;
import org.apache.flink.table.types.logical.DistinctType;
import org.apache.flink.table.types.logical.IntType;
import org.apache.flink.table.types.logical.LogicalType;
import org.apache.flink.table.types.logical.MapType;
import org.apache.flink.table.types.logical.MultisetType;
import org.apache.flink.table.types.logical.RawType;
import org.apache.flink.table.types.logical.RowType;
import org.apache.flink.table.types.logical.TypeInformationRawType;

import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getPrecision;
import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getScale;

/**
 * {@link TypeSerializer} of {@link LogicalType} for internal data structures.
 */
@Internal
public final class InternalSerializers {

	/**
	 * Creates a {@link TypeSerializer} for internal data structures of the given {@link LogicalType}.
	 */
	@SuppressWarnings("unchecked")
	public static <T> TypeSerializer<T> create(LogicalType type) {
		return (TypeSerializer<T>) createInternal(type);
	}

	/**
	 * Creates a {@link TypeSerializer} for internal data structures of the given {@link RowType}.
	 */
	public static <T> RowDataSerializer create(RowType type) {
		return (RowDataSerializer) createInternal(type);
	}

	private static TypeSerializer<?> createInternal(LogicalType type) {
		// ordered by type root definition
		switch (type.getTypeRoot()) {
			case CHAR:
			case VARCHAR:
				return StringDataSerializer.INSTANCE;
			case BOOLEAN:
				return BooleanSerializer.INSTANCE;
			case BINARY:
			case VARBINARY:
				return BytePrimitiveArraySerializer.INSTANCE;
			case DECIMAL:
				return new DecimalDataSerializer(getPrecision(type), getScale(type));
			case TINYINT:
				return ByteSerializer.INSTANCE;
			case SMALLINT:
				return ShortSerializer.INSTANCE;
			case INTEGER:
			case DATE:
			case TIME_WITHOUT_TIME_ZONE:
			case INTERVAL_YEAR_MONTH:
				return IntSerializer.INSTANCE;
			case BIGINT:
{'fraction_non_alphanumeric': 0.09356641352629316, 'fraction_numerical': 0.0011462960309499928, 'mean_word_length': 4.920271416454622, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5402056', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2021, 'n_words': 527}