Java Code Examples for org.apache.cassandra.io.sstable.CQLSSTableWriter#Builder

The following examples show how to use org.apache.cassandra.io.sstable.CQLSSTableWriter#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectMapper.java    From Rhombus with MIT License 6 votes vote down vote up
/**
 * Builds an SSTableWriter for a static table
 * @param sorted Defines if the SSTableWriters created by this should be set as sorted, which improves performance if
 *               rows are inserted in SSTable sort order, but throws exceptions if they are inserted in the wrong order.
 * @return A CQLSSTableWriter for this static table
 * @throws CQLGenerationException
 * @throws IOException
 */
private CQLSSTableWriter buildSSTableWriterForShardIndexTable(boolean sorted) throws CQLGenerationException, IOException {
	// Generate CQL create syntax
	String createCQL = this.cqlGenerator.makeCQLforShardIndexTableCreate().getQuery();

	// Generate CQL insert syntax
	String tableName = CObjectShardList.SHARD_INDEX_TABLE_NAME;
	String insertCQL = this.cqlGenerator.makeCQLforInsertNoValuesforShardIndex(tableName).getQuery();

	String SSTablePath = this.defaultSSTableOutputPath + "/" + keyspaceDefinition.getName() + "/" + tableName;
	if (!new File(SSTablePath).mkdir()) {
		throw new IOException("Failed to create new directory for SSTable writing at path: " + SSTablePath);
	}

	CQLSSTableWriter.Builder builder =
			CQLSSTableWriter.builder()
					.inDirectory(SSTablePath)
					.forTable(createCQL)
					.using(insertCQL);
	if (sorted) { builder = builder.sorted(); }
	return builder.build();
}
 
Example 2
Source File: ObjectMapper.java    From Rhombus with MIT License 6 votes vote down vote up
/**
 * Builds an SSTableWriter for a static table
 * @param definition Definition of object to build table for
 * @param sorted Defines if the SSTableWriters created by this should be set as sorted, which improves performance if
 *               rows are inserted in SSTable sort order, but throws exceptions if they are inserted in the wrong order.
 * @return A CQLSSTableWriter for this static table
 * @throws CQLGenerationException
 * @throws IOException
 */
private CQLSSTableWriter buildSSTableWriterForStaticTable(CDefinition definition, boolean sorted) throws CQLGenerationException, IOException {
	// Generate CQL create syntax
	String tableName = definition.getName();
	String createCQL = this.cqlGenerator.makeStaticTableCreate(definition).getQuery();

	// Generate CQL insert syntax
	String insertCQL = this.cqlGenerator.makeCQLforInsertNoValuesforStaticTable(tableName).getQuery();

	String SSTablePath = this.defaultSSTableOutputPath + "/" + keyspaceDefinition.getName() + "/" + tableName;
	if (!new File(SSTablePath).mkdir()) {
		throw new IOException("Failed to create new directory for SSTable writing at path: " + SSTablePath);
	}

	CQLSSTableWriter.Builder builder =
		CQLSSTableWriter.builder()
			.inDirectory(SSTablePath)
			.forTable(createCQL)
			.using(insertCQL);
	if (sorted) { builder = builder.sorted(); }
	return builder.build();
}
 
Example 3
Source File: ObjectMapper.java    From Rhombus with MIT License 6 votes vote down vote up
/**
 * Builds an SSTableWriter for a wide/index table
 * @param definition The definition this index/wide table is on
 * @param index The index/wide table to create an CQLSSTableWriter for
 * @param sorted Defines if the SSTableWriters created by this should be set as sorted, which improves performance if
 *               rows are inserted in SSTable sort order, but throws exceptions if they are inserted in the wrong order.
 * @return An CQLSSTableWriter for this wide table
 * @throws CQLGenerationException
 */
private CQLSSTableWriter buildSSTableWriterForWideTable(CDefinition definition, CIndex index, boolean sorted) throws CQLGenerationException, IOException {
	String indexTableName = CObjectCQLGenerator.makeTableName(definition, index);
	// Generate CQL create syntax
	String createCQL = this.cqlGenerator.makeWideTableCreate(definition, index).getQuery();

	// Generate CQL insert syntax
	// Just use 1 as the value for shardId, doesn't matter since we're not actually using values here
	String insertCQL = this.cqlGenerator.makeCQLforInsertNoValuesforWideTable(definition, indexTableName, 1L).getQuery();

	String SSTablePath = this.defaultSSTableOutputPath + "/" + keyspaceDefinition.getName() + "/" + indexTableName;
	if (!new File(SSTablePath).mkdir()) {
		throw new IOException("Failed to create new directory for SSTable writing at path: " + SSTablePath);
	}

	CQLSSTableWriter.Builder builder =
			CQLSSTableWriter.builder()
					.inDirectory(SSTablePath)
					.forTable(createCQL)
					.using(insertCQL);
	if (sorted) { builder = builder.sorted(); }
	return builder.build();
}