Skip to content

Instantly share code, notes, and snippets.

@shahamit
shahamit / Flattener.java
Created December 9, 2016 10:52
Flatten arbitrarily nested arrays
public static Integer[] flatten(Object[] inputArray) throws IllegalArgumentException {
if (inputArray == null) return null;
List<Integer> flatList = new ArrayList<Integer>();
for (Object element : inputArray) {
if (element instanceof Integer) {
flatList.add((Integer) element);
} else if (element instanceof Object[]) {
@shahamit
shahamit / CacheStoreTest
Created July 14, 2016 12:13
Class definition not found when working with Binary Objects
public void testLoad() {
IgniteCache<BinaryObject, BinaryObject> cache = ignite.getOrCreateCache(getConfig()).withKeepBinary();
String keyValue = "3M Company";
BinaryObjectBuilder keyBuilder = ignite.binary().builder("keyType")
.setField("f1", keyValue).hashCode(fieldValue.hashCode());
BinaryObject value = cache.get(keyBuilder.build());
logger.info("Loaded value {} for key {}", value, keyValue);
}
@shahamit
shahamit / BinaryObjectKeyValueCacheLoader.java
Created July 1, 2016 17:41
Includes code that tries to load an igniteCache<BinaryObject, BinaryObject>
public void loadTableWithCustomKeyColumns(Ignite ignite, Table table) {
CsvReader csvfile = null;
try (IgniteDataStreamer<BinaryObject, BinaryObject> streamer = ignite.dataStreamer(table.getName())) {
csvfile = new CsvReader(FILE_PATH + table.getName() + ".csv");
csvfile.readHeaders();
BinaryObjectBuilder keyBuilder = ignite.binary().builder(table.getCacheValueType());
BinaryObjectBuilder valueBuilder = ignite.binary().builder(table.getCacheValueType());
while (csvfile.readRecord()) {
@shahamit
shahamit / IgniteCacheLoader.java
Last active July 1, 2016 17:47
Includes code to load data into an Ignite<String, BinaryObject>. Data Load succeeds but iterating through the cache fails
public static CacheConfiguration<String, BinaryObject> getCacheConfigWithRandomIdAsKey(Table table) {
CacheConfiguration<String, BinaryObject> cfg = new CacheConfiguration<>();
cfg.setName(table.getName());
cfg.setCacheMode(table.getCacheMode());
setQueryEntities(table, cfg);
return cfg;
}
private static void setQueryEntities(Table table, CacheConfiguration cfg) {
QueryEntity qe = new QueryEntity();