@Test @SuppressWarnings("unchecked") public void testToKey() { PartitionStrategy strategy = new PartitionStrategy.Builder() .identity("id") .year("timestamp") .month("timestamp") .day("timestamp") .build(); StorageKey expected = new StorageKey(strategy); expected.replaceValues((List) Lists.newArrayList(1L, 2013, 11)); Assert.assertEquals(expected, convert.toKey( new Path(ROOT_PATH, "id=1/year=2013/month=11"), new StorageKey(strategy))); expected.replaceValues((List) Lists.newArrayList(1L, 2013)); Assert.assertEquals(expected, convert.toKey( new Path(ROOT_PATH, "id=1/year=2013"), new StorageKey(strategy))); expected.replaceValues((List) Lists.newArrayList(1L)); Assert.assertEquals(expected, convert.toKey( new Path(ROOT_PATH, "id=1"), new StorageKey(strategy))); expected.replaceValues(Collections.emptyList()); Assert.assertEquals(expected, convert.toKey( ROOT_PATH, new StorageKey(strategy))); }
public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); String truncatedPath = fromPath.toString(); if(truncatedPath.startsWith(rootPath.toString())){ truncatedPath = truncatedPath.substring(rootPath.toString().length()); } List<String> pathParts = new LinkedList<String>(); if(!truncatedPath.isEmpty()) { Path currentPath = new Path(truncatedPath); while (currentPath != null) { String name = currentPath.getName(); if(!name.isEmpty()) { pathParts.add(currentPath.getName()); } currentPath = currentPath.getParent(); } Collections.reverse(pathParts); } final List<Object> values = Lists.newArrayList( new Object[pathParts.size()]); for(int i = 0; i < pathParts.size(); i++){ values.set(i, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(i), pathParts.get(i))); } storage.replaceValues(values); return storage; }
PartialPathConversion extends PathConversion { public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); String truncatedPath = fromPath.toString(); if(truncatedPath.startsWith(rootPath.toString())){ truncatedPath = truncatedPath.substring(rootPath.toString().length()); } List<String> pathParts = new LinkedList<String>(); if(!truncatedPath.isEmpty()) { Path currentPath = new Path(truncatedPath); while (currentPath != null) { String name = currentPath.getName(); if(!name.isEmpty()) { pathParts.add(currentPath.getName()); } currentPath = currentPath.getParent(); } Collections.reverse(pathParts); } final List<Object> values = Lists.newArrayList( new Object[pathParts.size()]); for(int i = 0; i < pathParts.size(); i++){ values.set(i, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(i), pathParts.get(i))); } storage.replaceValues(values); return storage; } }
PartialPathConversion extends PathConversion { public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); String truncatedPath = fromPath.toString(); if(truncatedPath.startsWith(rootPath.toString())){ truncatedPath = truncatedPath.substring(rootPath.toString().length()); } List<String> pathParts = new LinkedList<String>(); if(!truncatedPath.isEmpty()) { Path currentPath = new Path(truncatedPath); while (currentPath != null) { String name = currentPath.getName(); if(!name.isEmpty()) { pathParts.add(currentPath.getName()); } currentPath = currentPath.getParent(); } Collections.reverse(pathParts); } final List<Object> values = Lists.newArrayList( new Object[pathParts.size()]); for(int i = 0; i < pathParts.size(); i++){ values.set(i, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(i), pathParts.get(i))); } storage.replaceValues(values); return storage; } PartialPathConversion(Path rootDirectory, Schema schema); }
PartialPathConversion extends PathConversion { public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); String truncatedPath = fromPath.toString(); if(truncatedPath.startsWith(rootPath.toString())){ truncatedPath = truncatedPath.substring(rootPath.toString().length()); } List<String> pathParts = new LinkedList<String>(); if(!truncatedPath.isEmpty()) { Path currentPath = new Path(truncatedPath); while (currentPath != null) { String name = currentPath.getName(); if(!name.isEmpty()) { pathParts.add(currentPath.getName()); } currentPath = currentPath.getParent(); } Collections.reverse(pathParts); } final List<Object> values = Lists.newArrayList( new Object[pathParts.size()]); for(int i = 0; i < pathParts.size(); i++){ values.set(i, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(i), pathParts.get(i))); } storage.replaceValues(values); return storage; } PartialPathConversion(Path rootDirectory, Schema schema); StorageKey toKey(Path fromPath, StorageKey storage); }
PartialPathConversion extends PathConversion { public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); String truncatedPath = fromPath.toString(); if(truncatedPath.startsWith(rootPath.toString())){ truncatedPath = truncatedPath.substring(rootPath.toString().length()); } List<String> pathParts = new LinkedList<String>(); if(!truncatedPath.isEmpty()) { Path currentPath = new Path(truncatedPath); while (currentPath != null) { String name = currentPath.getName(); if(!name.isEmpty()) { pathParts.add(currentPath.getName()); } currentPath = currentPath.getParent(); } Collections.reverse(pathParts); } final List<Object> values = Lists.newArrayList( new Object[pathParts.size()]); for(int i = 0; i < pathParts.size(); i++){ values.set(i, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(i), pathParts.get(i))); } storage.replaceValues(values); return storage; } PartialPathConversion(Path rootDirectory, Schema schema); StorageKey toKey(Path fromPath, StorageKey storage);  }