cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [2/3] git commit: allow using sstable2json on secondary index data
Date Fri, 20 Jan 2012 23:16:09 GMT
allow using sstable2json on secondary index data

patch by yukim and jbellis for CASSANDRA-3738


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/492d44e1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/492d44e1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/492d44e1

Branch: refs/heads/trunk
Commit: 492d44e1586eb6f73090ec29e7e997940cde314a
Parents: 5850178
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Fri Jan 20 16:45:24 2012 -0600
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Fri Jan 20 17:15:17 2012 -0600

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../apache/cassandra/io/sstable/SSTableReader.java |   25 +++++++++++++--
 .../org/apache/cassandra/tools/SSTableExport.java  |   25 ++-------------
 3 files changed, 26 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/492d44e1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 35fef0f..a47ae40 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/492d44e1/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index 8b4fc9e..10f868b 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -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

http://git-wip-us.apache.org/repos/asf/cassandra/blob/492d44e1/src/java/org/apache/cassandra/tools/SSTableExport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java
index 8c9ee5f..24a0d1c 100644
--- a/src/java/org/apache/cassandra/tools/SSTableExport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableExport.java
@@ -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);
     }
 
     /**


Mime
View raw message