Search in sources :

Example 36 with KettleValueException

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;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) IOException(java.io.IOException) EOFException(java.io.EOFException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) NumberFormat(java.text.NumberFormat)

Example 37 with KettleValueException

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;
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) KettleValueException(org.pentaho.di.core.exception.KettleValueException) SimpleDateFormat(java.text.SimpleDateFormat) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) IOException(java.io.IOException) EOFException(java.io.EOFException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 38 with KettleValueException

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++;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 39 with KettleValueException

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");
        }
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 40 with KettleValueException

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++;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Aggregations

KettleValueException (org.pentaho.di.core.exception.KettleValueException)127 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)35 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)35 KettleException (org.pentaho.di.core.exception.KettleException)25 KettleStepException (org.pentaho.di.core.exception.KettleStepException)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)16 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)13 IOException (java.io.IOException)12 Test (org.junit.Test)11 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)11 KettleFileException (org.pentaho.di.core.exception.KettleFileException)11 ParseException (java.text.ParseException)10 Date (java.util.Date)9 EOFException (java.io.EOFException)8 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 BigDecimal (java.math.BigDecimal)6