BarChartSink extends VisualizationOperator { @Override public void open() throws TexeraException { if (cursor != CLOSED) { return; } if (inputOperator == null) { throw new TexeraException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED); } inputOperator.open(); Schema schema = inputOperator.getOutputSchema(); Attribute nameColumn = schema.getAttribute(predicate.getNameColumn()); AttributeType nameColumnType = nameColumn.getType(); if (!nameColumnType.equals(AttributeType.STRING) && !nameColumnType.equals(AttributeType.TEXT)) { throw new DataflowException("Type of name column should be string or text."); } attributes.add(nameColumn); List<String> dataColumns = predicate.getDataColumn(); for (String name: dataColumns) { Attribute dataColumn = schema.getAttribute(name); AttributeType dataColumnType = dataColumn.getType(); if (!dataColumnType.equals(AttributeType.DOUBLE) && !dataColumnType.equals(AttributeType.INTEGER)) { throw new DataflowException(("Type of data column should be integer or double.")); } attributes.add(dataColumn); } outputSchema = new Schema.Builder().add(attributes).build(); cursor = OPENED; } BarChartSink(BarChartSinkPredicate predicate); @Override void open(); @Override void processTuples();  }
@Test public void test1() { TupleSourceOperator tupleSource = new TupleSourceOperator( BarChartSinkTestConstants.getTuples(), BarChartSinkTestConstants.BAR_SCHEMA); BarChartSink barChartSink = new BarChartSink(new BarChartSinkPredicate("name", Arrays.asList("grade"))); barChartSink.setInputOperator(tupleSource); barChartSink.open(); List<Tuple> resultTuples = barChartSink.collectAllTuples(); assertTrue(TestUtils.equals(BarChartSinkTestConstants.getResultTuples(), resultTuples)); }
@Test(expected = TexeraException.class) public void test2() { TupleSourceOperator tupleSource = new TupleSourceOperator( BarChartSinkTestConstants.getTuples(), BarChartSinkTestConstants.BAR_SCHEMA); BarChartSink barChartSink = new BarChartSink(new BarChartSinkPredicate("name", Arrays.asList(""))); barChartSink.setInputOperator(tupleSource); barChartSink.open(); barChartSink.collectAllTuples(); }
@Test(expected = TexeraException.class) public void test3() { TupleSourceOperator tupleSource = new TupleSourceOperator( BarChartSinkTestConstants.getTuples(), BarChartSinkTestConstants.BAR_SCHEMA); BarChartSink barChartSink = new BarChartSink(new BarChartSinkPredicate("name", Arrays.asList("gender"))); barChartSink.setInputOperator(tupleSource); barChartSink.open(); barChartSink.collectAllTuples(); }