mirror of https://github.com/apache/cassandra
allow using sstable2json on secondary index data
patch by yukim and jbellis for CASSANDRA-3738
This commit is contained in:
parent
5850178cb9
commit
492d44e158
|
|
@ -1,4 +1,5 @@
|
|||
1.0.8
|
||||
* allow using sstable2json on secondary index data (CASSANDRA-3738)
|
||||
* (cqlsh) add DESCRIBE COLUMNFAMILIES (CASSANDRA-3586)
|
||||
* (cqlsh) format blobs correctly and use colors to improve output
|
||||
readability (CASSANDRA-3726)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ import com.google.common.base.Function;
|
|||
import com.google.common.collect.Collections2;
|
||||
|
||||
import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.index.keys.KeysIndex;
|
||||
import org.apache.cassandra.dht.LocalPartitioner;
|
||||
import org.apache.cassandra.io.compress.CompressedRandomAccessReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -108,14 +111,30 @@ public class SSTableReader extends SSTable
|
|||
return count;
|
||||
}
|
||||
|
||||
public static SSTableReader open(Descriptor desc) throws IOException
|
||||
public static SSTableReader open(Descriptor descriptor) throws IOException
|
||||
{
|
||||
return open(desc, Schema.instance.getCFMetaData(desc.ksname, desc.cfname));
|
||||
CFMetaData metadata;
|
||||
if (descriptor.cfname.contains("."))
|
||||
{
|
||||
int i = descriptor.cfname.indexOf(".");
|
||||
String parentName = descriptor.cfname.substring(0, i);
|
||||
CFMetaData parent = Schema.instance.getCFMetaData(descriptor.ksname, parentName);
|
||||
ColumnDefinition def = parent.getColumnDefinitionForIndex(descriptor.cfname.substring(i + 1));
|
||||
metadata = CFMetaData.newIndexMetadata(parent, def, KeysIndex.indexComparator());
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata = Schema.instance.getCFMetaData(descriptor.ksname, descriptor.cfname);
|
||||
}
|
||||
return open(descriptor, metadata);
|
||||
}
|
||||
|
||||
public static SSTableReader open(Descriptor desc, CFMetaData metadata) throws IOException
|
||||
{
|
||||
return open(desc, componentsFor(desc), metadata, StorageService.getPartitioner());
|
||||
IPartitioner p = desc.cfname.contains(".")
|
||||
? new LocalPartitioner(metadata.getKeyValidator())
|
||||
: StorageService.getPartitioner();
|
||||
return open(desc, componentsFor(desc), metadata, p);
|
||||
}
|
||||
|
||||
public static SSTableReader open(Descriptor descriptor, Set<Component> components, CFMetaData metadata, IPartitioner partitioner) throws IOException
|
||||
|
|
|
|||
|
|
@ -25,13 +25,10 @@ import java.nio.ByteBuffer;
|
|||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.index.keys.KeysIndex;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
|
|
@ -246,7 +243,7 @@ public class SSTableExport
|
|||
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(ssTableFile));
|
||||
SSTableScanner scanner = reader.getDirectScanner();
|
||||
|
||||
IPartitioner<?> partitioner = StorageService.getPartitioner();
|
||||
IPartitioner<?> partitioner = reader.partitioner;
|
||||
|
||||
if (excludes != null)
|
||||
toExport.removeAll(Arrays.asList(excludes));
|
||||
|
|
@ -329,7 +326,7 @@ public class SSTableExport
|
|||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export an SSTable and write the resulting JSON to a PrintStream.
|
||||
*
|
||||
|
|
@ -341,23 +338,7 @@ public class SSTableExport
|
|||
*/
|
||||
public static void export(String ssTableFile, PrintStream outs, String[] excludes) throws IOException
|
||||
{
|
||||
Descriptor descriptor = Descriptor.fromFilename(ssTableFile);
|
||||
CFMetaData metadata;
|
||||
if (descriptor.cfname.contains("."))
|
||||
{
|
||||
// look up index metadata from parent
|
||||
int i = descriptor.cfname.indexOf(".");
|
||||
String parentName = descriptor.cfname.substring(0, i);
|
||||
CFMetaData parent = Schema.instance.getCFMetaData(descriptor.ksname, parentName);
|
||||
ColumnDefinition def = parent.getColumnDefinitionForIndex(descriptor.cfname.substring(i + 1));
|
||||
metadata = CFMetaData.newIndexMetadata(parent, def, KeysIndex.indexComparator());
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata = Schema.instance.getCFMetaData(descriptor.ksname, descriptor.cfname);
|
||||
}
|
||||
|
||||
export(SSTableReader.open(descriptor, metadata), outs, excludes);
|
||||
export(SSTableReader.open(Descriptor.fromFilename(ssTableFile)), outs, excludes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue