use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class Value method str2num.
public Value str2num(String pattern, String decimal, String grouping, String currency) throws KettleValueException {
if (isNull()) {
setType(VALUE_TYPE_STRING);
} else {
if (getType() == VALUE_TYPE_STRING) {
if (getString() == null) {
setNull();
setValue(0.0);
} else {
NumberFormat nf = NumberFormat.getInstance();
DecimalFormat df = (DecimalFormat) nf;
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
if (!Utils.isEmpty(pattern)) {
df.applyPattern(pattern);
}
if (!Utils.isEmpty(decimal)) {
dfs.setDecimalSeparator(decimal.charAt(0));
}
if (!Utils.isEmpty(grouping)) {
dfs.setGroupingSeparator(grouping.charAt(0));
}
if (!Utils.isEmpty(currency)) {
dfs.setCurrencySymbol(currency);
}
try {
df.setDecimalFormatSymbols(dfs);
setValue(df.parse(getString()).doubleValue());
} catch (Exception e) {
String message = "Couldn't convert string to number " + e.toString();
if (!Utils.isEmpty(pattern)) {
message += " pattern=" + pattern;
}
if (!Utils.isEmpty(decimal)) {
message += " decimal=" + decimal;
}
if (!Utils.isEmpty(grouping)) {
message += " grouping=" + grouping.charAt(0);
}
if (!Utils.isEmpty(currency)) {
message += " currency=" + currency;
}
throw new KettleValueException(message);
}
}
} else {
throw new KettleValueException("Function STR2NUM works only on strings");
}
}
return this;
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class Value method str2dat.
public Value str2dat(String arg0, String arg1) throws KettleValueException {
if (isNull()) {
setType(VALUE_TYPE_DATE);
} else {
// System.out.println("Convert string ["+string+"] to date using pattern '"+arg0+"'");
SimpleDateFormat df = new SimpleDateFormat();
DateFormatSymbols dfs = new DateFormatSymbols();
if (arg1 != null) {
dfs.setLocalPatternChars(arg1);
}
if (arg0 != null) {
df.applyPattern(arg0);
}
try {
value.setDate(df.parse(getString()));
setType(VALUE_TYPE_DATE);
setLength(-1, -1);
} catch (Exception e) {
setType(VALUE_TYPE_DATE);
setNull();
throw new KettleValueException("TO_DATE Couldn't convert String to Date" + e.toString());
}
}
return this;
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class UniqueRowsIT method checkRows.
/**
* Check the 2 lists comparing the rows in order. If they are not the same fail the test.
*/
public void checkRows(List<RowMetaAndData> rows1, List<RowMetaAndData> rows2) {
int idx = 1;
if (rows1.size() != rows2.size()) {
fail("Number of rows is not the same: " + rows1.size() + " and " + rows2.size());
}
Iterator<RowMetaAndData> it1 = rows1.iterator();
Iterator<RowMetaAndData> it2 = rows2.iterator();
while (it1.hasNext() && it2.hasNext()) {
RowMetaAndData rm1 = it1.next();
RowMetaAndData rm2 = it2.next();
Object[] r1 = rm1.getData();
Object[] r2 = rm2.getData();
if (rm1.size() != rm2.size()) {
fail("row nr " + idx + " is not equal");
}
int[] fields = new int[r1.length];
for (int ydx = 0; ydx < r1.length; ydx++) {
fields[ydx] = ydx;
}
try {
if (rm1.getRowMeta().compare(r1, r2, fields) != 0) {
fail("row nr " + idx + " is not equal");
}
} catch (KettleValueException e) {
fail("row nr " + idx + " is not equal");
}
idx++;
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class TransformationIT method checkRows.
/**
* Check the 2 lists comparing the rows in order. If they are not the same fail the test.
*/
public void checkRows(List<RowMetaAndData> rows1, List<RowMetaAndData> rows2) {
if (rows1.size() != rows2.size()) {
fail("Number of rows is not the same: " + rows1.size() + " and " + rows2.size());
}
ListIterator<RowMetaAndData> it1 = rows1.listIterator();
ListIterator<RowMetaAndData> it2 = rows2.listIterator();
while (it1.hasNext() && it2.hasNext()) {
RowMetaAndData rm1 = it1.next();
RowMetaAndData rm2 = it2.next();
Object[] r1 = rm1.getData();
Object[] r2 = rm2.getData();
if (rm1.size() != rm2.size()) {
fail("row nr " + it1.nextIndex() + " is not equal");
}
int[] fields = new int[r1.length];
for (int ydx = 0; ydx < r1.length; ydx++) {
fields[ydx] = ydx;
}
try {
if (rm1.getRowMeta().compare(r1, r2, fields) != 0) {
fail("row nr " + it1.nextIndex() + " is not equal");
}
} catch (KettleValueException e) {
fail("row nr " + it1.nextIndex() + " is not equal");
}
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ParameterSimpleTransIT method checkRows.
/**
* Check the 2 lists comparing the rows in order. If they are not the same fail the test.
*
* @param rows1
* first row set to compare
* @param rows2
* second row set to compare
*/
public void checkRows(List<RowMetaAndData> rows1, List<RowMetaAndData> rows2) {
int idx = 1;
if (rows1.size() != rows2.size()) {
fail("Number of rows is not the same: " + rows1.size() + " and " + rows2.size());
}
Iterator<RowMetaAndData> it1 = rows1.iterator();
Iterator<RowMetaAndData> it2 = rows2.iterator();
while (it1.hasNext() && it2.hasNext()) {
RowMetaAndData rm1 = it1.next();
RowMetaAndData rm2 = it2.next();
Object[] r1 = rm1.getData();
Object[] r2 = rm2.getData();
if (rm1.size() != rm2.size()) {
fail("row nr " + idx + " is not equal");
}
int[] fields = new int[rm1.size()];
for (int ydx = 0; ydx < rm1.size(); ydx++) {
fields[ydx] = ydx;
}
try {
if (rm1.getRowMeta().compare(r1, r2, fields) != 0) {
fail("row nr " + idx + " is not equal");
}
} catch (KettleValueException e) {
fail("row nr " + idx + " is not equal");
}
idx++;
}
}
Aggregations