use of org.knime.core.data.container.storage.TableStoreFormat in project knime-core by knime.
the class BufferedDataTable method save.
/**
* Saves the table to a directory and writes some settings to the argument
* NodeSettingsWO object. It will also write the reference table in case
* this node is responsible for it (i.e. this node created the reference
* table).
* @param dir The directory to write to.
* @param savedTableIDs Ids of tables that were previously saved, used to identify
* tables that are referenced by the same nodes multiple times.
* @param exec The progress monitor for cancellation.
* @throws IOException If writing fails.
* @throws CanceledExecutionException If canceled.
*/
void save(final File dir, final Set<Integer> savedTableIDs, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
NodeSettings s = new NodeSettings(CFG_TABLE_META);
Integer bufferedTableID = getBufferedTableId();
s.addInt(CFG_TABLE_ID, bufferedTableID);
File outFile = new File(dir, TABLE_FILE);
if (!savedTableIDs.add(bufferedTableID)) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_REFERENCE_IN_SAME_NODE);
} else if (m_delegate instanceof BufferedContainerTable) {
final TableStoreFormat format = ((BufferedContainerTable) m_delegate).getTableStoreFormat();
if (!DefaultTableStoreFormat.class.equals(format.getClass())) {
// use different identifier to cause old versions of KNIME to fail loading newer workflows
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_CONTAINER_CUSTOM);
s.addString(CFG_TABLE_CONTAINER_FORMAT, format.getClass().getName());
s.addString(CFG_TABLE_CONTAINER_FORMAT_VERSION, format.getVersion());
} else {
final DefaultTableStoreFormat defaultFormat = (DefaultTableStoreFormat) format;
if (!Arrays.asList(NONE, GZIP).contains(defaultFormat.getCompressionFormat())) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_CONTAINER_COMPRESS);
s.addString(CFG_TABLE_COMPRESSION_FORMAT, defaultFormat.getCompressionFormat().toString());
} else {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_CONTAINER);
}
}
m_delegate.saveToFile(outFile, s, exec);
} else {
if (m_delegate instanceof RearrangeColumnsTable) {
final ContainerTable containerTable = ((RearrangeColumnsTable) m_delegate).getAppendTable();
if (containerTable != null && containerTable instanceof BufferedContainerTable) {
final BufferedContainerTable appendTable = (BufferedContainerTable) containerTable;
final TableStoreFormat format = appendTable.getTableStoreFormat();
if (!DefaultTableStoreFormat.class.equals(format.getClass())) {
// use different identifier to cause old versions of KNIME to fail loading newer workflows
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_REARRANGE_COLUMN_CUSTOM);
s.addString(CFG_TABLE_CONTAINER_FORMAT, appendTable.getTableStoreFormat().getClass().getName());
s.addString(CFG_TABLE_CONTAINER_FORMAT_VERSION, appendTable.getTableStoreFormat().getVersion());
} else {
final DefaultTableStoreFormat defaultFormat = (DefaultTableStoreFormat) format;
if (!Arrays.asList(NONE, GZIP).contains(defaultFormat.getCompressionFormat())) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_REARRANGE_COLUMN_COMPRESS);
s.addString(CFG_TABLE_COMPRESSION_FORMAT, defaultFormat.getCompressionFormat().toString());
} else {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_REARRANGE_COLUMN);
}
}
} else {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_REARRANGE_COLUMN);
}
} else if (m_delegate instanceof TableSpecReplacerTable) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_NEW_SPEC);
} else if (m_delegate instanceof WrappedTable) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_WRAPPED);
} else if (m_delegate instanceof JoinedTable) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_JOINED);
} else if (m_delegate instanceof VoidTable) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_VOID);
} else if (m_delegate instanceof ConcatenateTable) {
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_CONCATENATE);
} else {
assert m_delegate instanceof ExtensionTable;
s.addString(CFG_TABLE_TYPE, TABLE_TYPE_EXTENSION);
}
BufferedDataTable[] references = m_delegate.getReferenceTables();
ArrayList<String> referenceDirs = new ArrayList<String>();
for (BufferedDataTable reference : references) {
if (reference.getOwner() == getOwner() && !savedTableIDs.contains(reference.getBufferedTableId())) {
int index = referenceDirs.size();
String dirName = "r" + index;
File subDir = new File(dir, dirName);
if (!subDir.mkdir() && !subDir.isDirectory()) {
throw new IOException("Could not create directory " + subDir.getAbsolutePath());
}
if (!subDir.canWrite()) {
throw new IOException("Unable to write directory " + subDir.getAbsolutePath());
}
referenceDirs.add(dirName);
reference.save(subDir, savedTableIDs, exec);
}
}
s.addStringArray(CFG_TABLE_REFERENCE, referenceDirs.toArray(new String[referenceDirs.size()]));
m_delegate.saveToFile(outFile, s, exec);
}
// only write the data file to the settings if it has been created
if (outFile.exists()) {
s.addString(CFG_TABLE_FILE_NAME, TABLE_FILE);
} else {
s.addString(CFG_TABLE_FILE_NAME, null);
}
saveSpec(getDataTableSpec(), dir);
File dataXML = new File(dir, TABLE_DESCRIPTION_FILE);
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(dataXML))) {
s.saveToXML(out);
}
}
use of org.knime.core.data.container.storage.TableStoreFormat in project knime-core by knime.
the class BufferSettings method getOutputFormat.
/**
* Returns the {@link TableStoreFormat} used to read and write the {@link Buffer Buffer's} content.
*
* @param spec the spec of the table to read/write
* @return the {@link TableStoreFormat}
*/
TableStoreFormat getOutputFormat(final DataTableSpec spec) {
if (m_outputFormat.accepts(spec)) {
LOGGER.debugWithFormat("Using table format %s", m_outputFormat.getClass().getName());
return m_outputFormat;
}
final TableStoreFormat storeFormat = TableStoreFormatRegistry.getInstance().getFormatFor(spec);
LOGGER.debugWithFormat("Cannot use table format '%s' as it does not support the table schema, " + "using '%s' instead", m_outputFormat.getClass().getName(), storeFormat.getClass().getName());
return storeFormat;
}
use of org.knime.core.data.container.storage.TableStoreFormat in project knime-core by knime.
the class BufferSettingsTest method testChangedValues.
/**
* Tests that values can be changed and that the default instance stays unchanged.
*/
@SuppressWarnings("static-method")
@Test
public void testChangedValues() {
final BufferSettings def = BufferSettings.getDefault();
final int lruCacheSize = def.getLRUCacheSize() * -1;
final boolean useLRU = !def.useLRU();
final TableStoreFormat outputFormat = new DefaultTableStoreFormat();
final BufferSettings settings = //
BufferSettings.getDefault().withOutputFormat(//
outputFormat).withLRU(//
useLRU).withLRUCacheSize(lruCacheSize);
assertEquals("Modified settings created wrong LRU cache size", lruCacheSize, settings.getLRUCacheSize());
assertEquals("Modified settings created wrong enable LRU flag", useLRU, settings.useLRU());
assertTrue("Modified settings created wrong output format", outputFormat == settings.getOutputFormat(new DataTableSpecCreator().createSpec()));
assertFalse("Default settings has been modified (output format)", def.getOutputFormat(new DataTableSpecCreator().createSpec()) == settings.getOutputFormat(new DataTableSpecCreator().createSpec()));
}
use of org.knime.core.data.container.storage.TableStoreFormat in project knime-core by knime.
the class BufferedDataTable method checkFormat.
private static void checkFormat(final NodeSettingsRO settings) throws InvalidSettingsException {
String formatFQN = CheckUtils.checkSettingNotNull(settings.getString(CFG_TABLE_CONTAINER_FORMAT), "Container format is null");
TableStoreFormat format = TableStoreFormatRegistry.getInstance().getTableStoreFormat(formatFQN);
String versionString = CheckUtils.checkSettingNotNull(settings.getString(CFG_TABLE_CONTAINER_FORMAT_VERSION), "Version string is null");
CheckUtils.checkSetting(format.validateVersion(versionString), "Unsupported version \"%s\" for table format \"%s\"", versionString, format.getClass().getName());
}
Aggregations