kunal642 commented on a change in pull request #3583: [CARBONDATA-3687] Support writing non-transactional carbondata files through hive URL: https://github.com/apache/carbondata/pull/3583#discussion_r388142780
########## File path: integration/hive/src/main/java/org/apache/carbondata/hive/util/HiveCarbonUtil.java ########## @@ -0,0 +1,332 @@ +/* + * 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.carbondata.hive.util; + +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.carbondata.common.Strings; +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.core.constants.CarbonCommonConstants; +import org.apache.carbondata.core.datastore.compression.CompressorFactory; +import org.apache.carbondata.core.datastore.filesystem.CarbonFile; +import org.apache.carbondata.core.datastore.impl.FileFactory; +import org.apache.carbondata.core.fileoperations.FileWriteOperation; +import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier; +import org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl; +import org.apache.carbondata.core.metadata.datatype.DataType; +import org.apache.carbondata.core.metadata.datatype.Field; +import org.apache.carbondata.core.metadata.datatype.StructField; +import org.apache.carbondata.core.metadata.schema.PartitionInfo; +import org.apache.carbondata.core.metadata.schema.SchemaEvolution; +import org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry; +import org.apache.carbondata.core.metadata.schema.SchemaReader; +import org.apache.carbondata.core.metadata.schema.partition.PartitionType; +import org.apache.carbondata.core.metadata.schema.table.CarbonTable; +import org.apache.carbondata.core.metadata.schema.table.TableInfo; +import org.apache.carbondata.core.metadata.schema.table.TableSchema; +import org.apache.carbondata.core.metadata.schema.table.TableSchemaBuilder; +import org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema; +import org.apache.carbondata.core.util.CarbonUtil; +import org.apache.carbondata.core.util.OutputFilesInfoHolder; +import org.apache.carbondata.core.util.path.CarbonTablePath; +import org.apache.carbondata.core.writer.ThriftWriter; +import org.apache.carbondata.processing.loading.constants.DataLoadProcessorConstants; +import org.apache.carbondata.processing.loading.model.CarbonDataLoadSchema; +import org.apache.carbondata.processing.loading.model.CarbonLoadModel; +import org.apache.carbondata.processing.util.TableOptionConstant; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.HiveMetaHook; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.log4j.Logger; + +public class HiveCarbonUtil { + + private static final Logger LOGGER = + LogServiceFactory.getLogService(HiveCarbonUtil.class.getName()); + + public static CarbonLoadModel getCarbonLoadModel(Configuration tableProperties) { + String[] tableUniqueName = tableProperties.get("name").split("\\."); + String databaseName = tableUniqueName[0]; + String tableName = tableUniqueName[1]; + String tablePath = tableProperties.get("location"); + String columns = tableProperties.get("columns"); + String sortColumns = tableProperties.get("sort_columns"); + String columnTypes = tableProperties.get("columns.types"); + String partitionColumns = tableProperties.get("partition_columns"); + String partitionColumnTypes = tableProperties.get("partition_columns.types"); + if (partitionColumns != null) { + columns = columns + "," + partitionColumns; + columnTypes = columnTypes + ":" + partitionColumnTypes; + } + String[] columnTypeArray = splitSchemaStringToArray(columnTypes); + String complexDelim = tableProperties.get("complex_delimiter", ""); + CarbonLoadModel carbonLoadModel = + getCarbonLoadModel(tableName, databaseName, tablePath, sortColumns, columns.split(","), + columnTypeArray, tableProperties); + carbonLoadModel.setCarbonTransactionalTable(true); + carbonLoadModel.getCarbonDataLoadSchema().getCarbonTable().setTransactionalTable(true); + for (String delim : complexDelim.split(",")) { + carbonLoadModel.setComplexDelimiter(delim); + } + return carbonLoadModel; + } + + public static CarbonLoadModel getCarbonLoadModel(Properties tableProperties, + Configuration configuration) { + String[] tableUniqueName = tableProperties.getProperty("name").split("\\."); + String databaseName = tableUniqueName[0]; + String tableName = tableUniqueName[1]; + String tablePath = tableProperties.getProperty("location"); + String columns = tableProperties.getProperty("columns"); + String sortColumns = tableProperties.getProperty("sort_columns"); + String[] columnTypes = splitSchemaStringToArray(tableProperties.getProperty("columns.types")); + String complexDelim = tableProperties.getProperty("complex_delimiter", ""); + CarbonLoadModel carbonLoadModel = + getCarbonLoadModel(tableName, databaseName, tablePath, sortColumns, columns.split(","), + columnTypes, configuration); + for (String delim : complexDelim.split(",")) { + carbonLoadModel.setComplexDelimiter(delim); + } + return carbonLoadModel; + } + + public static CarbonLoadModel getCarbonLoadModel(String tableName, String databaseName, Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services