@Test public void testToBoolean() throws Exception { List<Row> trueRows = Collections.singletonList( new Row("str_1", "true").add("str_2", "True").add("str_3", "TRUE") .add("int_col", 10000).add("double_col", 10000.00d) .add("short_col", new Short("10000")).add("long_col", 10000L) .add("float_col", 10000.0f).add("true_col", true) ); List<Row> falseRows = Collections.singletonList( new Row("str_1", "false").add("str_2", "False").add("str_3", "FALSE") .add("int_col", -10000).add("double_col", -10000.00d) .add("short_col", new Short("-10000")).add("long_col", -10000L) .add("float_col", -10000.0f).add("false_col", false) ); String[] directives = new String[] { "set-type str_1 bool", "set-type str_2 bool", "set-type str_3 bool", "set-type int_col Bool", "set-type double_col BOOL", "set-type short_col boolean", "set-type long_col Boolean", "set-type float_col BOOLEAN", "set-type bytes_col bool" }; List<Row> trueResults = TestingRig.execute(directives, trueRows); List<Row> falseResults = TestingRig.execute(directives, falseRows); Row trueRow = trueResults.get(0); Row falseRow = falseResults.get(0); for (int i = 0; i < trueRow.width(); i++) { Object trueObject = trueRow.getValue(i); Object falseObject = falseRow.getValue(i); Assert.assertTrue(trueObject instanceof Boolean); Assert.assertTrue(falseObject instanceof Boolean); Boolean trueValue = (Boolean) trueObject; Boolean falseValue = (Boolean) falseObject; Assert.assertTrue(trueValue); Assert.assertFalse(falseValue); } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ColumnConverter.convertType(NAME, row, col, type); } return rows; }
SetType implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ColumnConverter.convertType(NAME, row, col, type); } return rows; } }
SetType implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ColumnConverter.convertType(NAME, row, col, type); } return rows; }  }
SetType implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ColumnConverter.convertType(NAME, row, col, type); } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
SetType implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { ColumnConverter.convertType(NAME, row, col, type); } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }