All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.cask.wrangler.steps.Lower Maven / Gradle / Ivy

The newest version!
/*
 * Copyright © 2016 Cask Data, Inc.
 *
 * Licensed 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 co.cask.wrangler.steps;

import co.cask.wrangler.api.AbstractStep;
import co.cask.wrangler.api.PipelineContext;
import co.cask.wrangler.api.Row;
import co.cask.wrangler.api.SkipRowException;
import co.cask.wrangler.api.StepException;

/**
 * A Wrangler step for lower casing the 'col' value of type String.
 */
public class Lower extends AbstractStep {
  // Columns of the column to be lower cased.
  private String col;

  public Lower(int lineno, String detail, String col) {
    super(lineno, detail);
    this.col = col;
  }

  /**
   * Transforms a column value from any case to lower case.
   *
   * @param row Input {@link Row} to be wrangled by this step.
   * @param context Specifies the context of the pipeline.
   * @return Transformed {@link Row} in which the 'col' value is lower cased.
   * @throws StepException thrown when type of 'col' is not STRING.
   */
  @Override
  public Row execute(Row row, PipelineContext context) throws StepException, SkipRowException {
    int idx = row.find(col);

    if (idx != -1) {
      String value = (String) row.getValue(idx);
      if (value != null) {
        row.setValue(idx, value.toLowerCase());
      }
    } else {
      throw new StepException(toString() + " : " +
        col + " is not of type string. Please check the wrangle configuration."
      );
    }
    return row;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy