Package org.apache.cassandra.db

Examples of org.apache.cassandra.db.ColumnFamily$ColumnFamilySerializer


     * @throws ParseException for errors encountered parsing JSON input
     */
    public static void importJson(String jsonFile, String keyspace, String cf, String ssTablePath)
    throws IOException, ParseException
    {
        ColumnFamily cfamily = ColumnFamily.create(keyspace, cf);
        String cfType = cfamily.type();    // Super or Standard
        IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
        DataOutputBuffer dob = new DataOutputBuffer();
       
        try
        {
            JSONObject json = (JSONObject)JSONValue.parseWithException(new FileReader(jsonFile));
           
            SSTableWriter writer = new SSTableWriter(ssTablePath, json.size(), partitioner);
            List<DecoratedKey<?>> decoratedKeys = new ArrayList<DecoratedKey<?>>();
           
            for (String key : (Set<String>)json.keySet())
                decoratedKeys.add(partitioner.decorateKey(key));
            Collections.sort(decoratedKeys);

            for (DecoratedKey<?> rowKey : decoratedKeys)
            {
                if (cfType.equals("Super"))
                    addToSuperCF((JSONObject)json.get(rowKey.key), cfamily);
                else
                    addToStandardCF((JSONArray)json.get(rowKey.key), cfamily);
                          
                ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
                writer.append(rowKey, dob);
                dob.reset();
                cfamily.clear();
            }
           
            writer.closeAndOpenReader(0);
        }
        catch (ClassCastException cce)
View Full Code Here


        try
        {
            if (rows.size() > 1 || major)
            {
                ColumnFamily cf = null;
                for (IteratingRow row : rows)
                {
                    ColumnFamily thisCF;
                    try
                    {
                        thisCF = row.getColumnFamily();
                    }
                    catch (IOException e)
                    {
                        logger.error("Skipping row " + key + " in " + row.getPath(), e);
                        continue;
                    }
                    if (cf == null)
                    {
                        cf = thisCF;
                    }
                    else
                    {
                        cf.addAll(thisCF);
                    }
                }
                ColumnFamily cfPurged = major ? ColumnFamilyStore.removeDeleted(cf, gcBefore) : cf;
                if (cfPurged == null)
                    return null;
                ColumnFamily.serializer().serializeWithIndexes(cfPurged, buffer);
            }
            else
View Full Code Here

        return json.toString();
    }
   
    private static String serializeRow(IteratingRow row) throws IOException
    {
        ColumnFamily cf = row.getColumnFamily();
        AbstractType comparator = cf.getComparator();
        StringBuilder json = new StringBuilder(asKey(row.getKey().key));
       
        if (cf.isSuper())
        {
            json.append("{ ");

            Iterator<IColumn> iter = cf.getSortedColumns().iterator();
            while (iter.hasNext())
            {
                IColumn column = iter.next();
                json.append(asKey(bytesToHex(column.name())));
                json.append("{");
                json.append(asKey("deletedAt"));
                json.append(column.getMarkedForDeleteAt());
                json.append(", ");
                json.append(asKey("subColumns"));
                json.append(serializeColumns(column.getSubColumns(), comparator));
                json.append("}");
                if (iter.hasNext())
                    json.append(", ");
            }
           
            json.append("}");
        }
        else
        {
            json.append(serializeColumns(cf.getSortedColumns(), comparator));
        }
    
        return json.toString();
    }
View Full Code Here

        }
    }

    public static Message createMessage(String Keyspace, String Key, String CFName, List<ColumnFamily> ColumnFamiles)
    {
        ColumnFamily baseColumnFamily;
        DataOutputBuffer bufOut = new org.apache.cassandra.io.DataOutputBuffer();
        RowMutation rm;
        Message message;
        Column column;

        /* Get the first column family from list, this is just to get past validation */
        baseColumnFamily = new ColumnFamily(CFName, "Standard",DatabaseDescriptor.getComparator(Keyspace, CFName), DatabaseDescriptor.getSubComparator(Keyspace, CFName));
       
        for(ColumnFamily cf : ColumnFamiles) {
            bufOut.reset();
            try
            {
                ColumnFamily.serializer().serializeWithIndexes(cf, bufOut);
                byte[] data = new byte[bufOut.getLength()];
                System.arraycopy(bufOut.getData(), 0, data, 0, bufOut.getLength());

                column = new Column(cf.name().getBytes("UTF-8"), data, 0, false);
                baseColumnFamily.addColumn(column);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
View Full Code Here

            StorageService.instance().stopClient();
        }

        public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException
        {
            ColumnFamily columnFamily;
            String Keyspace = "Keyspace1";
            String CFName = "Super1";
            Message message;
            List<ColumnFamily> columnFamilies;
            columnFamilies = new LinkedList<ColumnFamily>();
            String line;

            /* Create a column family */
            columnFamily = ColumnFamily.create(Keyspace, CFName);
            while (values.hasNext()) {
                // Split the value (line based on your own delimiter)
                line = values.next().toString();
                String[] fields = line.split("\1");
                String SuperColumnName = fields[1];
                String ColumnName = fields[2];
                String ColumnValue = fields[3];
                int timestamp = 0;
                columnFamily.addColumn(new QueryPath(CFName, SuperColumnName.getBytes("UTF-8"), ColumnName.getBytes("UTF-8")), ColumnValue.getBytes(), timestamp);
            }

            columnFamilies.add(columnFamily);

            /* Get serialized message to send to cluster */
 
View Full Code Here

        StageManager.getStage(Stage.TRACING).execute(new WrappedRunnable()
        {
            public void runMayThrow() throws Exception
            {
                CFMetaData cfMeta = CFMetaData.TraceEventsCf;
                ColumnFamily cf = ColumnFamily.create(cfMeta);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source")), FBUtilities.getBroadcastAddress());
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("thread")), threadName);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source_elapsed")), elapsed);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("activity")), message);
                RowMutation mutation = new RowMutation(Tracing.TRACE_KS, sessionIdBytes);
View Full Code Here

     */
    private static void writeMeta(PrintStream out, AbstractColumnContainer columnContainer)
    {
        if (columnContainer instanceof ColumnFamily)
        {
            ColumnFamily columnFamily = (ColumnFamily) columnContainer;
            if (!columnFamily.deletionInfo().equals(DeletionInfo.LIVE))
            {
                // begin meta
                writeKey(out, "metadata");
                writeDeletionInfo(out, columnFamily.deletionInfo().getTopLevelDeletion());
                out.print(",");
            }
            return;
        }

View Full Code Here

     * @param key Decorated Key for the required row
     * @param out output stream
     */
    private static void serializeRow(SSTableIdentityIterator row, DecoratedKey key, PrintStream out)
    {
        ColumnFamily columnFamily = row.getColumnFamily();
        boolean isSuperCF = columnFamily.isSuper();
        CFMetaData cfMetaData = columnFamily.metadata();
        AbstractType<?> comparator = columnFamily.getComparator();

        out.print("{");
        writeKey(out, "key");
        writeJSON(out, bytesToHex(key.key));
        out.print(",");

        writeMeta(out, columnFamily);

        writeKey(out, "columns");
        out.print(isSuperCF ? "{" : "[");

        if (isSuperCF)
        {
            while (row.hasNext())
            {
                SuperColumn scol = (SuperColumn)row.next();
                assert scol instanceof IColumn;
                IColumn column = (IColumn)scol;
                writeKey(out, comparator.getString(column.name()));
                out.print("{");
                writeMeta(out, scol);
                writeKey(out, "subColumns");
                out.print("[");
                serializeIColumns(column.getSubColumns().iterator(), out, columnFamily.getSubComparator(), cfMetaData);
                out.print("]");
                out.print("}");

                if (row.hasNext())
                    out.print(", ");
View Full Code Here

                versionSources.add(current.right);
            }

            protected Row getReduced()
            {
                ColumnFamily resolved = RowRepairResolver.resolveSuperset(versions);
                RowRepairResolver.maybeScheduleRepairs(resolved, table, key, versions, versionSources);
                versions.clear();
                versionSources.clear();
                return new Row(key, resolved);
            }
View Full Code Here

            ByteBuffer bytes2 = in2.readBytes(indexSize2);

            assert bytes1.equals(bytes2);

            // cf metadata
            ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
            ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
            ColumnFamily.serializer().deserializeFromSSTableNoColumns(cf1, in1);
            ColumnFamily.serializer().deserializeFromSSTableNoColumns(cf2, in2);
            assert cf1.getLocalDeletionTime() == cf2.getLocalDeletionTime();
            assert cf1.getMarkedForDeleteAt() == cf2.getMarkedForDeleteAt();  
            // columns
            int columns = in1.readInt();
            assert columns == in2.readInt();
            for (int i = 0; i < columns; i++)
            {
                IColumn c1 = cf1.getColumnSerializer().deserialize(in1);
                IColumn c2 = cf2.getColumnSerializer().deserialize(in2);
                assert c1.equals(c2);
            }
            // that should be everything
            assert in1.available() == 0;
            assert in2.available() == 0;
View Full Code Here

TOP

Related Classes of org.apache.cassandra.db.ColumnFamily$ColumnFamilySerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.