use of java.util.Spliterator.ORDERED in project hazelcast by hazelcast.
the class SqlCompactTest method randomEntryFrom.
@SuppressWarnings({ "OptionalGetWithoutIsPresent", "unchecked", "rawtypes" })
private static Entry<Data, Data> randomEntryFrom(String mapName) {
NodeEngine engine = getNodeEngine(instance());
MapService service = engine.getService(MapService.SERVICE_NAME);
MapServiceContext context = service.getMapServiceContext();
return Arrays.stream(context.getPartitionContainers()).map(partitionContainer -> partitionContainer.getExistingRecordStore(mapName)).filter(Objects::nonNull).flatMap(store -> {
Iterator<Entry<Data, Record>> iterator = store.iterator();
return stream(spliteratorUnknownSize(iterator, ORDERED), false);
}).map(entry -> entry(entry.getKey(), (Data) entry.getValue().getValue())).findFirst().get();
}
use of java.util.Spliterator.ORDERED in project hazelcast by hazelcast.
the class SqlPortableTest method randomEntryFrom.
@SuppressWarnings({ "OptionalGetWithoutIsPresent", "unchecked", "rawtypes" })
private static Entry<Data, Data> randomEntryFrom(String mapName) {
NodeEngine engine = getNodeEngine(instance());
MapService service = engine.getService(MapService.SERVICE_NAME);
MapServiceContext context = service.getMapServiceContext();
return Arrays.stream(context.getPartitionContainers()).map(partitionContainer -> partitionContainer.getExistingRecordStore(mapName)).filter(Objects::nonNull).flatMap(store -> {
Iterator<Entry<Data, Record>> iterator = store.iterator();
return stream(spliteratorUnknownSize(iterator, ORDERED), false);
}).map(entry -> entry(entry.getKey(), (Data) entry.getValue().getValue())).findFirst().get();
}
use of java.util.Spliterator.ORDERED in project hazelcast by hazelcast.
the class CsvReadFileFnProvider method createReadFileFn.
@SuppressWarnings("unchecked")
@Nonnull
@Override
public <T> FunctionEx<Path, Stream<T>> createReadFileFn(@Nonnull FileFormat<T> format) {
CsvFileFormat<T> csvFileFormat = (CsvFileFormat<T>) format;
// Format is not Serializable
Class<?> formatClazz = csvFileFormat.clazz();
return path -> {
FileInputStream fis = new FileInputStream(path.toFile());
MappingIterator<T> iterator;
Function<T, T> projection = identity();
if (formatClazz == String[].class) {
ObjectReader reader = new CsvMapper().enable(Feature.WRAP_AS_ARRAY).readerFor(String[].class).with(CsvSchema.emptySchema().withSkipFirstDataRow(false));
iterator = reader.readValues(fis);
if (!iterator.hasNext()) {
throw new JetException("Header row missing in " + path);
}
String[] header = (String[]) iterator.next();
List<String> fieldNames = csvFileFormat.fieldNames();
if (fieldNames != null) {
projection = (Function<T, T>) createFieldProjection(header, fieldNames);
}
} else {
iterator = new CsvMapper().readerFor(formatClazz).withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).with(CsvSchema.emptySchema().withHeader()).readValues(fis);
}
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, ORDERED), false).map(projection).onClose(() -> uncheckRun(fis::close));
};
}
use of java.util.Spliterator.ORDERED in project sql-boot by sql-boot.
the class JdbcSqlQuery method getMapStream.
private Stream<Map<String, Object>> getMapStream(final String sqlText) {
logger.info(sqlText);
final SqlRowSet rowSet = new JdbcTemplate(dataSource).queryForRowSet(sqlText);
Iterator<Map<String, Object>> iterator = new Iterator<Map<String, Object>>() {
@Override
public boolean hasNext() {
return rowSet.next();
}
@Override
public Map<String, Object> next() {
return stream(rowSet.getMetaData().getColumnNames()).map(v -> {
Object object = rowSet.getObject(v);
if (object instanceof SerialClob) {
try {
return new SimpleEntry<>(v, (Object) ((SerialClob) object).getSubString(1, (int) ((SerialClob) object).length()));
} catch (SerialException e) {
e.printStackTrace();
}
}
return new SimpleEntry<>(v, object);
}).collect(toMap(k -> k.getKey(), /*.toLowerCase()*/
v -> ofNullable(v.getValue()).orElse(nullAlias), (a, b) -> a, LinkedHashMap::new));
}
};
return stream(spliteratorUnknownSize(iterator, ORDERED), false);
}
Aggregations