public static int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath, IPartitioner<?> partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.currentTimeMillis();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_OBJECT
while (parser.nextToken() != null)
{
parser.nextToken();
parser.skipChildren();
if (parser.getCurrentName() == null) continue;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
if (key != null)
{
String tokenName = parser.nextToken().name();
if (tokenName.equals("START_ARRAY"))
{
if (columnFamily.getType() == ColumnFamilyType.Super)
{
throw new RuntimeException("Can't write Standard columns to the Super Column Family.");
}
List<?> columns = parser.readValueAs(new TypeReference<List<?>>() {});
addToStandardCF(columns, columnFamily);
}
else if (tokenName.equals("START_OBJECT"))
{
if (columnFamily.getType() == ColumnFamilyType.Standard)
{
throw new RuntimeException("Can't write Super columns to the Standard Column Family.");
}
Map<?, ?> columns = parser.readValueAs(new TypeReference<Map<?, ?>>() {});
addToSuperCF(columns, columnFamily);
}
else
{
throw new UnsupportedOperationException("Only Array or Hash allowed as row content.");