com.clickzetta.client.jdbc.arrow.ConvertUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickzetta-java Show documentation
Show all versions of clickzetta-java Show documentation
The java SDK for clickzetta's Lakehouse
package com.clickzetta.client.jdbc.arrow;
import com.clickzetta.client.jdbc.arrow.SqlTypes;
import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.proto.Common;
import org.apache.calcite.avatica.proto.Common.ColumnMetaData.Builder;
import com.clickzetta.client.jdbc.core.CZColumnMetaData;
import java.sql.Types;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Convert Fields To Column MetaData List functions.
*/
public final class ConvertUtils {
private ConvertUtils() {
}
/**
* Convert Fields To Column MetaData List functions.
*
* @param fields list of {@link CZColumnMetaData}.
* @return list of {@link ColumnMetaData}.
*/
public static List convertToColumnMetaDataList(final List fields) {
return Stream.iterate(0, Math::incrementExact).limit(fields.size())
.map(index -> {
final CZColumnMetaData field = fields.get(index);
final Builder builder = Common.ColumnMetaData.newBuilder()
.setOrdinal(index)
.setColumnName(field.getColumnName())
.setLabel(field.getColumnName())
.setNullable(field.isNullable());
setOnColumnMetaDataBuilder(builder, field);
builder.setType(Common.AvaticaType.newBuilder()
.setId(SqlTypes.getSqlTypeIdFromCZColumnMetaData(field))
.setName(SqlTypes.getSqlTypeNameFromCZColumnMetaData(field))
.build());
return ColumnMetaData.fromProto(builder.build());
}).collect(Collectors.toList());
}
/**
* Set on Column MetaData Builder.
*
* @param builder {@link Builder}
* @param czColumnMetaData {@link CZColumnMetaData}
*/
public static void setOnColumnMetaDataBuilder(final Builder builder,
final CZColumnMetaData czColumnMetaData) {
int sqlType = czColumnMetaData.getColumnType();
if (sqlType == Types.DECIMAL) {
builder.setPrecision(czColumnMetaData.getPrecision());
builder.setScale(czColumnMetaData.getScale());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy