<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.carbondata.processing.newflow.converter.impl;

import org.apache.carbondata.common.logging.LogService;
import org.apache.carbondata.common.logging.LogServiceFactory;
import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonMeasure;
import org.apache.carbondata.core.util.DataTypeUtil;
import org.apache.carbondata.processing.newflow.DataField;
import org.apache.carbondata.processing.newflow.converter.BadRecordLogHolder;
import org.apache.carbondata.processing.newflow.converter.FieldConverter;
import org.apache.carbondata.processing.newflow.exception.CarbonDataLoadingException;
import org.apache.carbondata.processing.newflow.row.CarbonRow;

/**
 * Converter for measure
 */
public class MeasureFieldConverterImpl implements FieldConverter {

  private static final LogService LOGGER =
      LogServiceFactory.getLogService(MeasureFieldConverterImpl.class.getName());

  private int index;

  private DataType dataType;

  private CarbonMeasure measure;

  private String nullformat;

  public MeasureFieldConverterImpl(DataField dataField, String nullformat, int index) {
    this.dataType = dataField.getColumn().getDataType();
    this.measure = (CarbonMeasure) dataField.getColumn();
    this.nullformat = nullformat;
    this.index = index;
  }

  @Override
  public void convert(CarbonRow row, BadRecordLogHolder logHolder)
      throws CarbonDataLoadingException {
    String value = row.getString(index);
    Object output;
    if (value == null) {
      logHolder.setReason(
          "The value " + " \"" + value + "\"" + " with column name " + measure.getColName()
              + " and column data type " + dataType + " is not a valid " + dataType + " type.");
      row.update(null, index);
    } else if(value.equals(nullformat)) {
      row.update(null, index);
    } else {
      try {
        output = DataTypeUtil.getMeasureValueBasedOnDataType(value, dataType, measure);
        row.update(output, index);
      } catch (NumberFormatException e) {
        LOGGER.warn(
            "Cant not convert : " + value + " to Numeric type value. Value considered as null.");
        logHolder.setReason(
            "The value " + " \"" + value + "\"" + " with column name " + measure.getColName()
                + " and column data type " + dataType + " is not a valid " + dataType + " type.");
        output = null;
        row.update(output, index);
      }
    }

  }
}<commit_msg>[CARBONDATA-558] Fix load performace issue when use_kettle=false This closes #459<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.carbondata.processing.newflow.converter.impl;

import org.apache.carbondata.common.logging.LogService;
import org.apache.carbondata.common.logging.LogServiceFactory;
import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonMeasure;
import org.apache.carbondata.core.constants.CarbonCommonConstants;
import org.apache.carbondata.core.util.DataTypeUtil;
import org.apache.carbondata.processing.newflow.DataField;
import org.apache.carbondata.processing.newflow.converter.BadRecordLogHolder;
import org.apache.carbondata.processing.newflow.converter.FieldConverter;
import org.apache.carbondata.processing.newflow.exception.CarbonDataLoadingException;
import org.apache.carbondata.processing.newflow.row.CarbonRow;

/**
 * Converter for measure
 */
public class MeasureFieldConverterImpl implements FieldConverter {

  private static final LogService LOGGER =
      LogServiceFactory.getLogService(MeasureFieldConverterImpl.class.getName());

  private int index;

  private DataType dataType;

  private CarbonMeasure measure;

  private String nullformat;

  public MeasureFieldConverterImpl(DataField dataField, String nullformat, int index) {
    this.dataType = dataField.getColumn().getDataType();
    this.measure = (CarbonMeasure) dataField.getColumn();
    this.nullformat = nullformat;
    this.index = index;
  }

  @Override
  public void convert(CarbonRow row, BadRecordLogHolder logHolder)
      throws CarbonDataLoadingException {
    String value = row.getString(index);
    Object output;
    boolean isNull = CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(value);
    if (value == null || value.length() == 0 || isNull) {
      logHolder.setReason(
          "The value " + " \"" + value + "\"" + " with column name " + measure.getColName()
              + " and column data type " + dataType + " is not a valid " + dataType + " type.");
      row.update(null, index);
    } else if(value.equals(nullformat)) {
      row.update(null, index);
    } else {
      try {
        output = DataTypeUtil.getMeasureValueBasedOnDataType(value, dataType, measure);
        row.update(output, index);
      } catch (NumberFormatException e) {
        LOGGER.warn(
            "Cant not convert : " + value + " to Numeric type value. Value considered as null.");
        logHolder.setReason(
            "The value " + " \"" + value + "\"" + " with column name " + measure.getColName()
                + " and column data type " + dataType + " is not a valid " + dataType + " type.");
        output = null;
        row.update(output, index);
      }
    }

  }
}
{'fraction_non_alphanumeric': 0.09781507741282014, 'fraction_numerical': 0.0021704529011720448, 'mean_word_length': 3.6420416386836805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5533667', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1878, 'n_words': 549}