Package org.apache.cassandra.thrift

Examples of org.apache.cassandra.thrift.CqlRow$CqlRowTupleScheme


                        col.setValue(value(c)).setTimestamp(c.timestamp());
                    break;
            }
            thriftColumns.add(col);
        }
        return new CqlRow(key, thriftColumns);
    }
View Full Code Here


            values.clear();
            valueMap.clear();
        }
        if (rSetIter != null && rSetIter.hasNext())
        {
            CqlRow row = rSetIter.next();
            curRowKey = row.getKey();
            List<Column> cols = row.getColumns();
            for (Column col : cols)
            {
                byte[] name = col.getName();
                byte[] value = col.getValue();
                TypedColumn c = decoder.makeCol(keyspace, columnFamily, name, value);
View Full Code Here

            result.schema = new CqlMetadata(Collections.<ByteBuffer, String>emptyMap(),
                                            Collections.<ByteBuffer, String>emptyMap(),
                                            "AsciiType",
                                            "LongType");
            List<Column> columns = Collections.singletonList(new Column(countColumn).setValue(ByteBufferUtil.bytes((long) cqlRows.size())));
            result.rows = Collections.singletonList(new CqlRow(countColumn, columns));
            return result;
        }
        else
        {
            // otherwise create resultset from query results
View Full Code Here

                            default:
                                throw new AssertionError();
                        }
                        thriftColumns.add(col);
                    }
                    cqlRows.add(new CqlRow(row.key.key, thriftColumns));
                }
            }
            else if (cfDef.isComposite)
            {
                // Sparse case: group column in cqlRow when composite prefix is equal
                CompositeType composite = (CompositeType)cfDef.cfm.comparator;
                int last = composite.types.size() - 1;

                ByteBuffer[] previous = null;
                Map<ByteBuffer, IColumn> group = new HashMap<ByteBuffer, IColumn>();
                for (IColumn c : row.cf)
                {
                    if (c.isMarkedForDelete())
                        continue;

                    ByteBuffer[] current = composite.split(c.name());
                    // If current differs from previous, we've just finished a group
                    if (previous != null && !isSameRow(previous, current))
                    {
                        cqlRows.add(handleGroup(selection, row.key.key, previous, group, schema));
                        group = new HashMap<ByteBuffer, IColumn>();
                    }

                    // Accumulate the current column
                    group.put(current[last], c);
                    previous = current;
                }
                // Handle the last group
                if (previous != null)
                    cqlRows.add(handleGroup(selection, row.key.key, previous, group, schema));
            }
            else
            {
                if (row.cf.getLiveColumnCount() == 0)
                    continue;

                // Static case: One cqlRow for all columns
                thriftColumns = new ArrayList<Column>(selection.size());

                // Respect selection order
                for (Pair<CFDefinition.Name, Selector> p : selection)
                {
                    CFDefinition.Name name = p.left;
                    Selector selector = p.right;

                    if (name.kind == CFDefinition.Name.Kind.KEY_ALIAS)
                    {
                        thriftColumns.add(new Column(selector.id().key).setValue(row.key.key).setTimestamp(-1L));
                        continue;
                    }

                    IColumn c = row.cf.getColumn(name.name.key);
                    thriftColumns.add(makeReturnColumn(selector, c));
                }
                cqlRows.add(new CqlRow(row.key.key, thriftColumns));
            }
        }

        orderResults(cqlRows);
View Full Code Here

                default:
                    throw new AssertionError();
            }
            thriftColumns.add(col);
        }
        return new CqlRow(key, thriftColumns);
    }
View Full Code Here

                    result.schema = new CqlMetadata(Collections.<ByteBuffer, String>emptyMap(),
                                                    Collections.<ByteBuffer, String>emptyMap(),
                                                    "AsciiType",
                                                    "LongType");
                    List<Column> columns = Collections.singletonList(new Column(countBytes).setValue(ByteBufferUtil.bytes((long) rows.size())));
                    result.rows = Collections.singletonList(new CqlRow(countBytes, columns));
                    return result;
                }

                // otherwise create resultset from query results
                result.schema = new CqlMetadata(new HashMap<ByteBuffer, String>(),
                                                new HashMap<ByteBuffer, String>(),
                                                TypeParser.getShortName(metadata.comparator),
                                                TypeParser.getShortName(metadata.getDefaultValidator()));
                List<CqlRow> cqlRows = new ArrayList<CqlRow>(rows.size());
                for (org.apache.cassandra.db.Row row : rows)
                {
                    List<Column> thriftColumns = new ArrayList<Column>();
                    if (select.isColumnRange())
                    {
                        if (select.isFullWildcard())
                        {
                            // prepend key
                            ByteBuffer keyName = ByteBufferUtil.bytes(metadata.getCQL2KeyName());
                            thriftColumns.add(new Column(keyName).setValue(row.key.key).setTimestamp(-1));
                            result.schema.name_types.put(keyName, TypeParser.getShortName(AsciiType.instance));
                            result.schema.value_types.put(keyName, TypeParser.getShortName(metadata.getKeyValidator()));
                        }

                        // preserve comparator order
                        if (row.cf != null)
                        {
                            for (org.apache.cassandra.db.Column c : row.cf.getSortedColumns())
                            {
                                if (c.isMarkedForDelete(now))
                                    continue;

                                ColumnDefinition cd = metadata.getColumnDefinitionFromColumnName(c.name());
                                if (cd != null)
                                    result.schema.value_types.put(c.name(), TypeParser.getShortName(cd.getValidator()));

                                thriftColumns.add(thriftify(c));
                            }
                        }
                    }
                    else
                    {
                        String keyString = metadata.getCQL2KeyName();

                        // order columns in the order they were asked for
                        for (Term term : select.getColumnNames())
                        {
                            if (term.getText().equalsIgnoreCase(keyString))
                            {
                                // preserve case of key as it was requested
                                ByteBuffer requestedKey = ByteBufferUtil.bytes(term.getText());
                                thriftColumns.add(new Column(requestedKey).setValue(row.key.key).setTimestamp(-1));
                                result.schema.name_types.put(requestedKey, TypeParser.getShortName(AsciiType.instance));
                                result.schema.value_types.put(requestedKey, TypeParser.getShortName(metadata.getKeyValidator()));
                                continue;
                            }

                            if (row.cf == null)
                                continue;

                            ByteBuffer name;
                            try
                            {
                                name = term.getByteBuffer(metadata.comparator, variables);
                            }
                            catch (InvalidRequestException e)
                            {
                                throw new AssertionError(e);
                            }

                            ColumnDefinition cd = metadata.getColumnDefinitionFromColumnName(name);
                            if (cd != null)
                                result.schema.value_types.put(name, TypeParser.getShortName(cd.getValidator()));
                            org.apache.cassandra.db.Column c = row.cf.getColumn(name);
                            if (c == null || c.isMarkedForDelete(now))
                                thriftColumns.add(new Column().setName(name));
                            else
                                thriftColumns.add(thriftify(c));
                        }
                    }

                    // Create a new row, add the columns to it, and then add it to the list of rows
                    CqlRow cqlRow = new CqlRow();
                    cqlRow.key = row.key.key;
                    cqlRow.columns = thriftColumns;
                    if (select.isColumnsReversed())
                        Collections.reverse(cqlRow.columns);
                    cqlRows.add(cqlRow);
View Full Code Here

                Column col = new Column(ByteBufferUtil.bytes(metadata.names.get(i).toString()));
                col.setValue(row.get(i));
                thriftCols.add(col);
            }
            // The key of CqlRow shoudn't be needed in CQL3
            cqlRows.add(new CqlRow(ByteBufferUtil.EMPTY_BYTE_BUFFER, thriftCols));
        }
        CqlResult res = new CqlResult(CqlResultType.ROWS);
        res.setRows(cqlRows).setSchema(schema);
        return res;
    }
View Full Code Here

        CqlResult cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '1'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        List<CqlRow> cqlRows = cqlResult.getRows();
        CqlRow cqlRow = cqlRows.get(0);

        boolean personNameFound = false;
        boolean ageFound = false;

        for (Column column : cqlRow.getColumns())
        {
            String columnName = new String(column.getName(), Constants.ENCODING);
            if (columnName.equals("ttl(PERSON_NAME)"))
            {
                Assert.assertEquals(5, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
                personNameFound = true;
            }
            else if (columnName.equals("ttl(AGE)"))
            {
                Assert.assertEquals(5, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
                ageFound = true;
            }
        }

        Assert.assertTrue(personNameFound && ageFound);
        Thread.sleep(5000);

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '1'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();

        try
        {
            cqlRow = cqlRows.get(0);
            Assert.fail("PERSON_NAME and AGE column not deleted even though a TTL of 5 seconds was specified while writing to cassandra.");
        }
        catch (IndexOutOfBoundsException ioobe)
        {
            Assert.assertTrue(cqlRows.isEmpty());
        }
        // checking for update query.

        Object p2 = prepareData("2", 10);
        em.persist(p2);
        em.clear();

        ttlValues = new HashMap<String, Integer>();
        ttlValues.put("PERSONCASSANDRA", new Integer(10));
        em.setProperty("ttl.per.request", true);
        em.setProperty("ttl.values", ttlValues);

        Query q = em.createQuery("update PersonCassandra p set p.personName=''KK MISHRA'' where p.personId=2");
        q.executeUpdate();

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '2'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();
        cqlRow = cqlRows.get(0);

        personNameFound = false;
        ageFound = false;

        for (Column column : cqlRow.getColumns())
        {
            String columnName = new String(column.getName(), Constants.ENCODING);
            if (columnName.equals("ttl(PERSON_NAME)"))
            {
                Assert.assertEquals(10, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
                personNameFound = true;
            }
            else if (columnName.equals("ttl(AGE)"))
            {
                Assert.assertEquals(null, column.getValue());
                ageFound = true;
            }           
        }

        Assert.assertTrue(personNameFound && ageFound);
        Thread.sleep(10000);

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '2'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();
        cqlRow = cqlRows.get(0);
        for (Column column : cqlRow.getColumns())
        {
            String columnName = new String(column.getName(), Constants.ENCODING);
            if (columnName.equals("ttl(PERSON_NAME)"))
            {
                Assert.assertEquals(null, null);
                personNameFound = true;
            }
            else if (columnName.equals("ttl(AGE)"))
            {
                Assert.assertEquals(null, column.getValue());
                ageFound = true;
            }
            if (columnName.equals("PERSON_NAME"))
            {
                Assert.fail("PERSON_NAME column not deleted even though a TTL of 10 seconds was specified while writing to cassandra.");
            }
        }

        // TTL per session.

        ttlValues = new HashMap<String, Integer>();
        ttlValues.put("PERSONCASSANDRA", new Integer(10));
        em.setProperty("ttl.per.session", true);
        em.setProperty("ttl.values", ttlValues);

        Object p3 = prepareData("3", 10);
        em.persist(p3);
        em.clear();

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '3'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();
        cqlRow = cqlRows.get(0);

        personNameFound = false;
        ageFound = false;

        for (Column column : cqlRow.getColumns())
        {
            String columnName = new String(column.getName(), Constants.ENCODING);
            if (columnName.equals("ttl(PERSON_NAME)"))
            {
                Assert.assertEquals(10, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
                personNameFound = true;
            }
            else if (columnName.equals("ttl(AGE)"))
            {
                Assert.assertEquals(10, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
                ageFound = true;
            }
        }

        Assert.assertTrue(personNameFound && ageFound);
        Thread.sleep(10000);

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '3'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();
        try
        {
            cqlRow = cqlRows.get(0);
            Assert.fail("PERSON_NAME and AGE column not deleted even though a TTL of 5 seconds was specified while writing to cassandra.");
        }
        catch (IndexOutOfBoundsException ioobe)
        {
            Assert.assertTrue(cqlRows.isEmpty());
        }

        Object p4 = prepareData("4", 10);
        em.persist(p4);
        em.clear();

        cqlResult = CassandraCli.client.execute_cql3_query(ByteBuffer
                .wrap("Select ttl(\"PERSON_NAME\"), ttl(\"AGE\") from \"PERSONCASSANDRA\" where \"personId\" = '4'"
                        .getBytes()), Compression.NONE, ConsistencyLevel.ONE);

        cqlRows = cqlResult.getRows();
        cqlRow = cqlRows.get(0);
        personNameFound = false;
        ageFound = false;

        for (Column column : cqlRow.getColumns())
        {
            String columnName = new String(column.getName(), Constants.ENCODING);
            if (columnName.equals("ttl(PERSON_NAME)"))
            {
                Assert.assertEquals(10, ByteBufferUtil.toInt(ByteBuffer.wrap(column.getValue())));
View Full Code Here

                    returnedEntities = new ArrayList<Object>(result.getRowsSize());
                    Iterator<CqlRow> iter = result.getRowsIterator();
                    while (iter.hasNext()) {
                        Object e = null;

                        CqlRow row = iter.next();
                        Object rowKey = null;

                        ThriftRow thriftRow = null;
                        thriftRow =
                            new ThriftRow(rowKey, entityMetadata.getTableName(), row.getColumns(),
                                new ArrayList<SuperColumn>(0), new ArrayList<CounterColumn>(0),
                                new ArrayList<CounterSuperColumn>(0));

                        e =
                            dataHandler.populateEntity(thriftRow, entityMetadata, KunderaCoreUtils.getEntity(e),
                                relationalField, relationalField != null && !relationalField.isEmpty());

                        e = populateSecondaryTableData(relationalField, dataHandler, isCql3Enabled, entityMetadata, e);

                        if (e != null) {
                            returnedEntities.add(e);
                        } else if (isNative) {
                            returnedEntities.add(row.getColumns().get(0));
                        }
                    }
                }
            } catch (Exception e) {
                log.error("Error while executing native CQL query Caused by {}.", e);
View Full Code Here

                    result = (CqlResult) executeCQLQuery(queryBuilder.toString(), isCql3Enabled);

                    if (result != null && (result.getRows() != null || result.getRowsSize() > 0)) {
                        Iterator<CqlRow> iterator = result.getRowsIterator();
                        while (iterator.hasNext()) {
                            CqlRow cqlRow = iterator.next();

                            ThriftRow tr = null;
                            tr =
                                new ThriftRow(null, entityMetadata.getTableName(), cqlRow.getColumns(),
                                    new ArrayList<SuperColumn>(0), new ArrayList<CounterColumn>(0),
                                    new ArrayList<CounterSuperColumn>(0));

                            e =
                                dataHandler.populateEntity(tr, entityMetadata, KunderaCoreUtils.getEntity(e),
View Full Code Here

TOP

Related Classes of org.apache.cassandra.thrift.CqlRow$CqlRowTupleScheme

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.