return empty BufferedDataTable

In execute method i use the following code to return empty rows:

return new BufferedDataTable[] {};

but got error

java.lang.IllegalStateException: Invalid result. Execution failed. Reason: Incorrect implementation; the execute method in TSDBNodeModel returned null or an incorrect number of output tables.

Hi @lou,

This error is thrown because the number of output tables specified in the constructor of your NodeModel differs from the number of tables you return.

protected YourNodeNodeModel() {
    super(1 /* Number of input ports*/, 1 /* Number of output ports*/);

If you set the number of output ports to zero, your node will execute without that exception. In that case you can also just return null; instead of return new BufferedDataTable[] {};.


yes i set one output port,

super(0, 1);

and use

return new BufferedDataTable[] {};

and got the exception.

You return 0 tables but you’re saying you’re going to return 1 in the constructor.

Do you want no table or an empty table? If you want an empty table you need to create the table and then return it rather than an empty array of tables.

1 Like
return new BufferedDataTable[] {}; 

Are those code return empty table?

I think that’s returning an empty array?

I think you need to do something like:

BufferedDatatable emptyTable = createEmptyTable(exec);
return new BufferedDataTable {emptyTable}

Where the createEmptyTable() method creates a table with no columns and no rows. I’ve not got a working KNIME development environment on the machine I’m on to create a working example.

thanks,In my scenario when there is empty array response , i return empty table
i just tried the following method:

private BufferedDataTable[] createEmptyTable(BufferedDataContainer container) {
	int columns = container.getTable().getDataTableSpec().getNumColumns();
	DataCell[] cells = new DataCell[columns];
	for(int i=0;i<columns;i++) {
		cells[i] = new StringCell("");
	DataRow row = new DefaultRow(new RowKey(""), cells);
	BufferedDataTable out = container.getTable();
	return new BufferedDataTable[] { out };

get error:

java.lang.IllegalStateException: Cannot get table: container is not closed.

because my table cell is dynamic,so i need to get the columns to create empty row.

Hi @lou,
do you want to return a table without any content at all, or, as in your example, with a single row containing empty strings? If you only want an empty table with no rows and no columns, you can use this:

private BufferedDataTable[] createEmptyTable(final ExecutionContext exec) {
    BufferedDataContainer container = exec.createDataContainer(new DataTableSpecCreator().createSpec());
    BufferedDataTable out = container.getTable();
    return new BufferedDataTable[] {out};

If you want it to have some columns, you have to modify this line: BufferedDataContainer container = exec.createDataContainer(new DataTableSpecCreator().createSpec());. Here you have to create a table spec matching your required columns and then pass that to the container creation.
Kind regards

// Edit: I changed the code a bit because the container must be closed before accessing the table using getTable().

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.