Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1886 : Cleanup XML of transform Row Normaliser #1910

Merged
merged 5 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public boolean processRow() throws HopException {
}

List<Integer> normFieldList;
int i;
int e;

if (first) { // INITIALISE

Expand All @@ -65,7 +63,6 @@ public boolean processRow() throws HopException {
data.inputRowMeta = getInputRowMeta();
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
int normFieldsLength = meta.getNormaliserFields().length;
data.typeToFieldIndex = new HashMap<>();
String typeValue;
int dataFieldNr;
Expand All @@ -75,8 +72,8 @@ public boolean processRow() throws HopException {
data.type_occ = new ArrayList<>();
data.maxlen = 0;

for (i = 0; i < normFieldsLength; i++) {
typeValue = meta.getNormaliserFields()[i].getValue();
for (NormaliserField field : meta.getNormaliserFields()) {
typeValue = field.getValue();
if (!data.type_occ.contains(typeValue)) {
data.type_occ.add(typeValue);
}
Expand All @@ -93,13 +90,13 @@ public boolean processRow() throws HopException {
// On a test data set with 2500 fields and about 36000 input rows (outputting over 22m
// rows), the time went from
// 12min to about 1min 35sec.
dataFieldNr = data.inputRowMeta.indexOfValue(meta.getNormaliserFields()[i].getName());
dataFieldNr = data.inputRowMeta.indexOfValue(field.getName());
if (dataFieldNr < 0) {
logError(
BaseMessages.getString(
PKG,
"Normaliser.Log.CouldNotFindFieldInRow",
meta.getNormaliserFields()[i].getName()));
field.getName()));
setErrors(1);
stopAll();
return false;
Expand All @@ -119,7 +116,7 @@ public boolean processRow() throws HopException {
Set<String> normaliserFields = meta.getFieldNames();
int irmSize = data.inputRowMeta.size();

for (i = 0; i < irmSize; i++) {
for (int i = 0; i < irmSize; i++) {
IValueMeta v = data.inputRowMeta.getValueMeta(Integer.valueOf(i));
// Backwards compatibility - old loop called Const.indexofstring which uses equalsIgnoreCase
if (!normaliserFields.contains(v.getName().toLowerCase())) {
Expand All @@ -144,7 +141,7 @@ public boolean processRow() throws HopException {
// Now do the normalization
// Loop over the unique occurrences of the different types.
//
for (e = 0; e < typeOccSize; e++) {
for (int e = 0; e < typeOccSize; e++) {
typeValue = data.type_occ.get(e);

// Create an output row per type
Expand All @@ -154,7 +151,7 @@ public boolean processRow() throws HopException {

// Copy the input row data, excluding the fields that are normalized...
//
for (i = 0; i < copyFldNrsSz; i++) {
for (int i = 0; i < copyFldNrsSz; i++) {
nr = data.copyFieldnrs.get(i);
outputRowData[outputIndex++] = r[nr];
}
Expand All @@ -167,7 +164,7 @@ public boolean processRow() throws HopException {
//
normFieldList = data.typeToFieldIndex.get(typeValue);
int normFieldListSz = normFieldList.size();
for (i = 0; i < normFieldListSz; i++) {
for (int i = 0; i < normFieldListSz; i++) {
value = r[normFieldList.get(i)];
outputRowData[outputIndex++] = value;
}
Expand All @@ -185,13 +182,4 @@ public boolean processRow() throws HopException {

return true;
}

@Override
public boolean init() {
if (super.init()) {
// Add init code here.
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String open() {
shell.setText(BaseMessages.getString(PKG, "NormaliserDialog.Shell.Title"));

int middle = props.getMiddlePct();
int margin = props.getMargin();
int margin = PropsUi.getMargin();

// Buttons at the bottom
wOk = new Button(shell, SWT.PUSH);
Expand Down Expand Up @@ -156,8 +156,7 @@ public String open() {
wlFields.setLayoutData(fdlFields);

final int fieldsCols = 3;
final int fieldsRows = input.getNormaliserFields().length;

final int fieldsRows = input.getNormaliserFields().size();
colinf = new ColumnInfo[fieldsCols];
colinf[0] =
new ColumnInfo(
Expand Down Expand Up @@ -244,16 +243,17 @@ public void getData() {
wTypefield.setText(input.getTypeField());
}

for (int i = 0; i < input.getNormaliserFields().length; i++) {
for (int i = 0; i < input.getNormaliserFields().size(); i++) {
TableItem item = wFields.table.getItem(i);
if (input.getNormaliserFields()[i].getName() != null) {
item.setText(NAME_INDEX, input.getNormaliserFields()[i].getName());
NormaliserField field = input.getNormaliserFields().get(i);
if (field.getName() != null) {
item.setText(NAME_INDEX, field.getName());
}
if (input.getNormaliserFields()[i].getValue() != null) {
item.setText(VALUE_INDEX, input.getNormaliserFields()[i].getValue());
if (field.getValue() != null) {
item.setText(VALUE_INDEX,field.getValue());
}
if (input.getNormaliserFields()[i].getNorm() != null) {
item.setText(NORM_INDEX, input.getNormaliserFields()[i].getNorm());
if (field.getNorm() != null) {
item.setText(NORM_INDEX, field.getNorm());
}
}

Expand Down Expand Up @@ -281,15 +281,17 @@ private void ok() {

int i;

int nrFields = wFields.nrNonEmpty();
input.allocate(nrFields);
int nrFields = wFields.nrNonEmpty();
input.getNormaliserFields().clear();

// CHECKSTYLE:Indentation:OFF
for (i = 0; i < nrFields; i++) {
TableItem item = wFields.getNonEmpty(i);
input.getNormaliserFields()[i].setName(item.getText(NAME_INDEX));
input.getNormaliserFields()[i].setValue(item.getText(VALUE_INDEX));
input.getNormaliserFields()[i].setNorm(item.getText(NORM_INDEX));
NormaliserField field = new NormaliserField();
field.setName(item.getText(NAME_INDEX));
field.setValue(item.getText(VALUE_INDEX));
field.setNorm(item.getText(NORM_INDEX));
input.getNormaliserFields().add(field);
}

dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.hop.pipeline.transforms.normaliser;

import org.apache.hop.metadata.api.HopMetadataProperty;
import java.util.Objects;

public class NormaliserField {

@HopMetadataProperty(key="name", injectionKey = "NAME", injectionKeyDescription = "NormaliserMeta.Injection.NAME")
private String name;

@HopMetadataProperty(key="value", injectionKey = "VALUE", injectionKeyDescription = "NormaliserMeta.Injection.VALUE")
private String value;

@HopMetadataProperty(key="norm", injectionKey = "NORMALISED", injectionKeyDescription = "NormaliserMeta.Injection.NORMALISED")
private String norm;

public NormaliserField() {
// Do nothing
}

public NormaliserField(NormaliserField field) {
this.name = field.name;
this.value = field.value;
this.norm = field.norm;
}

/** @return the name */
public String getName() {
return name;
}

/** @param name the name to set */
public void setName(String name) {
this.name = name;
}

/** @return the value */
public String getValue() {
return value;
}

/** @param value the value to set */
public void setValue(String value) {
this.value = value;
}

/** @return the norm */
public String getNorm() {
return norm;
}

/** @param norm the norm to set */
public void setNorm(String norm) {
this.norm = norm;
}

@Override
public int hashCode() {
return Objects.hash(name, norm, value);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NormaliserField other = (NormaliserField) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (norm == null) {
if (other.norm != null) {
return false;
}
} else if (!norm.equals(other.norm)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}
Loading