Java Code Examples for com.datastax.driver.mapping.Mapper#Option

The following examples show how to use com.datastax.driver.mapping.Mapper#Option . 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: CassandraPojoOutputFormat.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a Session to Cassandra and initializes the prepared statement.
 *
 * @param taskNumber The number of the parallel instance.
 */
@Override
public void open(int taskNumber, int numTasks) {
	this.session = cluster.connect();
	MappingManager mappingManager = new MappingManager(session);
	this.mapper = mappingManager.mapper(outputClass);
	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultSaveOptions(optionsArray);
		}
	}
	this.callback = new FutureCallback<Void>() {
		@Override
		public void onSuccess(Void ignored) {
			onWriteSuccess();
		}

		@Override
		public void onFailure(Throwable t) {
			onWriteFailure(t);
		}
	};
}
 
Example 2
Source File: CassandraPojoSink.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration configuration) {
	super.open(configuration);
	try {
		this.mappingManager = new MappingManager(session);
		this.mapper = mappingManager.mapper(clazz);
		if (options != null) {
			Mapper.Option[] optionsArray = options.getMapperOptions();
			if (optionsArray != null) {
				this.mapper.setDefaultSaveOptions(optionsArray);
			}
		}
	} catch (Exception e) {
		throw new RuntimeException("Cannot create CassandraPojoSink with input: " + clazz.getSimpleName(), e);
	}
}
 
Example 3
Source File: CassandraPojoOutputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a Session to Cassandra and initializes the prepared statement.
 *
 * @param taskNumber The number of the parallel instance.
 */
@Override
public void open(int taskNumber, int numTasks) {
	this.session = cluster.connect();
	MappingManager mappingManager = new MappingManager(session);
	this.mapper = mappingManager.mapper(outputClass);
	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultSaveOptions(optionsArray);
		}
	}
	this.callback = new FutureCallback<Void>() {
		@Override
		public void onSuccess(Void ignored) {
			onWriteSuccess();
		}

		@Override
		public void onFailure(Throwable t) {
			onWriteFailure(t);
		}
	};
}
 
Example 4
Source File: CassandraPojoSink.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration configuration) {
	super.open(configuration);
	try {
		this.mappingManager = new MappingManager(session);
		this.mapper = mappingManager.mapper(clazz);
		if (options != null) {
			Mapper.Option[] optionsArray = options.getMapperOptions();
			if (optionsArray != null) {
				this.mapper.setDefaultSaveOptions(optionsArray);
			}
		}
	} catch (Exception e) {
		throw new RuntimeException("Cannot create CassandraPojoSink with input: " + clazz.getSimpleName(), e);
	}
}
 
Example 5
Source File: CassandraPojoOutputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a Session to Cassandra and initializes the prepared statement.
 *
 * @param taskNumber The number of the parallel instance.
 */
@Override
public void open(int taskNumber, int numTasks) {
	this.session = cluster.connect();
	MappingManager mappingManager = new MappingManager(session);
	this.mapper = mappingManager.mapper(outputClass);
	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultSaveOptions(optionsArray);
		}
	}
	this.callback = new FutureCallback<Void>() {
		@Override
		public void onSuccess(Void ignored) {
			onWriteSuccess();
		}

		@Override
		public void onFailure(Throwable t) {
			onWriteFailure(t);
		}
	};
}
 
Example 6
Source File: CassandraPojoSink.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration configuration) {
	super.open(configuration);
	try {
		this.mappingManager = new MappingManager(session);
		this.mapper = mappingManager.mapper(clazz);
		if (options != null) {
			Mapper.Option[] optionsArray = options.getMapperOptions();
			if (optionsArray != null) {
				this.mapper.setDefaultSaveOptions(optionsArray);
			}
		}
	} catch (Exception e) {
		throw new RuntimeException("Cannot create CassandraPojoSink with input: " + clazz.getSimpleName(), e);
	}
}
 
Example 7
Source File: CassandraPojoInputFormat.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open(InputSplit split) {
	this.session = cluster.connect();
	MappingManager manager = new MappingManager(session);

	Mapper<OUT> mapper = manager.mapper(inputClass);

	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultGetOptions(optionsArray);
		}
	}
	this.resultSet = mapper.map(session.execute(query));
}
 
Example 8
Source File: CassandraPojoInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(InputSplit split) {
	this.session = cluster.connect();
	MappingManager manager = new MappingManager(session);

	Mapper<OUT> mapper = manager.mapper(inputClass);

	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultGetOptions(optionsArray);
		}
	}
	this.resultSet = mapper.map(session.execute(query));
}
 
Example 9
Source File: CassandraPojoInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(InputSplit split) {
	this.session = cluster.connect();
	MappingManager manager = new MappingManager(session);

	Mapper<OUT> mapper = manager.mapper(inputClass);

	if (mapperOptions != null) {
		Mapper.Option[] optionsArray = mapperOptions.getMapperOptions();
		if (optionsArray != null) {
			mapper.setDefaultGetOptions(optionsArray);
		}
	}
	this.resultSet = mapper.map(session.execute(query));
}
 
Example 10
Source File: CassandraConnectorITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testCassandraBatchPojoFormat() throws Exception {

	session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));

	OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)});

	List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20)
		.mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0))
		.collect(Collectors.toList());
	try {
		sink.configure(new Configuration());
		sink.open(0, 1);
		for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) {
			sink.writeRecord(customCassandraAnnotatedPojo);
		}
	} finally {
		sink.close();
	}
	ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));
	Assert.assertEquals(20, rs.all().size());

	InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class);
	List<CustomCassandraAnnotatedPojo> result = new ArrayList<>();

	try {
		source.configure(new Configuration());
		source.open(null);
		while (!source.reachedEnd()) {
			CustomCassandraAnnotatedPojo temp = source.nextRecord(null);
			result.add(temp);
		}
	} finally {
		source.close();
	}

	Assert.assertEquals(20, result.size());
	result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));
	customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));

	assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos));
}
 
Example 11
Source File: CassandraConnectorITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCassandraBatchPojoFormat() throws Exception {

	session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));

	OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)});

	List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20)
		.mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0))
		.collect(Collectors.toList());
	try {
		sink.configure(new Configuration());
		sink.open(0, 1);
		for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) {
			sink.writeRecord(customCassandraAnnotatedPojo);
		}
	} finally {
		sink.close();
	}
	ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));
	Assert.assertEquals(20, rs.all().size());

	InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class);
	List<CustomCassandraAnnotatedPojo> result = new ArrayList<>();

	try {
		source.configure(new Configuration());
		source.open(null);
		while (!source.reachedEnd()) {
			CustomCassandraAnnotatedPojo temp = source.nextRecord(null);
			result.add(temp);
		}
	} finally {
		source.close();
	}

	Assert.assertEquals(20, result.size());
	result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));
	customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));

	assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos));
}
 
Example 12
Source File: CassandraConnectorITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCassandraBatchPojoFormat() throws Exception {

	session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));

	OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)});

	List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20)
		.mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0))
		.collect(Collectors.toList());
	try {
		sink.configure(new Configuration());
		sink.open(0, 1);
		for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) {
			sink.writeRecord(customCassandraAnnotatedPojo);
		}
	} finally {
		sink.close();
	}
	ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME));
	Assert.assertEquals(20, rs.all().size());

	InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class);
	List<CustomCassandraAnnotatedPojo> result = new ArrayList<>();

	try {
		source.configure(new Configuration());
		source.open(null);
		while (!source.reachedEnd()) {
			CustomCassandraAnnotatedPojo temp = source.nextRecord(null);
			result.add(temp);
		}
	} finally {
		source.close();
	}

	Assert.assertEquals(20, result.size());
	result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));
	customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter));

	assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos));
}
 
Example 13
Source File: MapperOptions.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of {@link com.datastax.driver.mapping.Mapper.Option} that are used configure the mapper.
 *
 * @return array of options used to configure the mapper.
 */
Mapper.Option[] getMapperOptions();
 
Example 14
Source File: MapperOptions.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of {@link com.datastax.driver.mapping.Mapper.Option} that are used configure the mapper.
 *
 * @return array of options used to configure the mapper.
 */
Mapper.Option[] getMapperOptions();
 
Example 15
Source File: MapperOptions.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of {@link com.datastax.driver.mapping.Mapper.Option} that are used configure the mapper.
 *
 * @return array of options used to configure the mapper.
 */
Mapper.Option[] getMapperOptions();