Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.Tree


        Map<String, String> strategyOptions = new HashMap<String, String>();

        // each child node is ^(PAIR $key $value)
        for (int j = 0; j < options.getChildCount(); j++)
        {
            Tree optionPair = options.getChild(j);

            // current $key
            String key = CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
            // current $value
            String val = CliUtils.unescapeSQLString(optionPair.getChild(1).getText());

            strategyOptions.put(key, val);
        }

        return strategyOptions;
View Full Code Here


     * @return byte[] - string value as byte[]
     */
    private ByteBuffer convertValueByFunction(Tree functionCall, CfDef columnFamily, ByteBuffer columnName, boolean withUpdate)
    {
        String functionName = functionCall.getChild(0).getText();
        Tree argumentTree = functionCall.getChild(1);
        String functionArg  = (argumentTree == null) ? "" : CliUtils.unescapeSQLString(argumentTree.getText());
        AbstractType<?> validator = getTypeByFunction(functionName);

        try
        {

View Full Code Here

    }

    // Execute a CLI Statement
    public void executeCLIStatement(String statement) throws CharacterCodingException, TException, TimedOutException, NotFoundException, NoSuchFieldException, InvalidRequestException, UnavailableException, InstantiationException, IllegalAccessException, ClassNotFoundException
    {
        Tree tree = CliCompiler.compileQuery(statement);
        try
        {
            switch (tree.getType())
            {
                case CliParser.NODE_EXIT:
                    cleanupAndExit();
                    break;
                case CliParser.NODE_THRIFT_GET:
                    executeGet(tree);
                    break;
                case CliParser.NODE_THRIFT_GET_WITH_CONDITIONS:
                    executeGetWithConditions(tree);
                    break;
                case CliParser.NODE_HELP:
                    executeHelp(tree);
                    break;
                case CliParser.NODE_THRIFT_SET:
                    executeSet(tree);
                    break;
                case CliParser.NODE_THRIFT_DEL:
                    executeDelete(tree);
                    break;
                case CliParser.NODE_THRIFT_COUNT:
                    executeCount(tree);
                    break;
                case CliParser.NODE_ADD_KEYSPACE:
                    executeAddKeySpace(tree.getChild(0));
                    break;
                case CliParser.NODE_ADD_COLUMN_FAMILY:
                    executeAddColumnFamily(tree.getChild(0));
                    break;
                case CliParser.NODE_UPDATE_KEYSPACE:
                    executeUpdateKeySpace(tree.getChild(0));
                    break;
                case CliParser.NODE_UPDATE_COLUMN_FAMILY:
                    executeUpdateColumnFamily(tree.getChild(0));
                    break;
                case CliParser.NODE_DEL_COLUMN_FAMILY:
                    executeDelColumnFamily(tree);
                    break;
                case CliParser.NODE_DEL_KEYSPACE:
                    executeDelKeySpace(tree);
                    break;
                case CliParser.NODE_SHOW_CLUSTER_NAME:
                    executeShowClusterName();
                    break;
                case CliParser.NODE_SHOW_VERSION:
                    executeShowVersion();
                    break;
                case CliParser.NODE_SHOW_KEYSPACES:
                    executeShowKeySpaces();
                    break;
                case CliParser.NODE_SHOW_SCHEMA:
                    executeShowSchema(tree);
                    break;
                case CliParser.NODE_DESCRIBE:
                    executeDescribe(tree);
                    break;
                case CliParser.NODE_DESCRIBE_CLUSTER:
                    executeDescribeCluster();
                    break;
                case CliParser.NODE_USE_TABLE:
                    executeUseKeySpace(tree);
                    break;
                case CliParser.NODE_TRACE_NEXT_QUERY:
                    executeTraceNextQuery();
                    break;
                case CliParser.NODE_CONNECT:
                    executeConnect(tree);
                    break;
                case CliParser.NODE_LIST:
                    executeList(tree);
                    break;
                case CliParser.NODE_TRUNCATE:
                    executeTruncate(tree.getChild(0).getText());
                    break;
                case CliParser.NODE_ASSUME:
                    executeAssumeStatement(tree);
                    break;
                case CliParser.NODE_CONSISTENCY_LEVEL:
                    executeConsistencyLevelStatement(tree);
                    break;
                case CliParser.NODE_THRIFT_INCR:
                    executeIncr(tree, 1L);
                    break;
                case CliParser.NODE_THRIFT_DECR:
                    executeIncr(tree, -1L);
                    break;
                case CliParser.NODE_DROP_INDEX:
                    executeDropIndex(tree);
                    break;

                case CliParser.NODE_NO_OP:
                    // comment lines come here; they are treated as no ops.
                    break;
                default:
                    sessionState.err.println("Invalid Statement (Type: " + tree.getType() + ")");
                    if (sessionState.batch)
                        System.exit(2);
                    break;
            }
        }
View Full Code Here

            throws TException, InvalidRequestException, UnavailableException, TimedOutException
    {
        if (!CliMain.isConnected() || !hasKeySpace())
            return;

        Tree columnFamilySpec = statement.getChild(0);

        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

        ColumnParent colParent = new ColumnParent(columnFamily).setSuper_column((ByteBuffer) null);

        if (columnSpecCnt != 0)
        {
            Tree columnTree = columnFamilySpec.getChild(2);

            byte[] superColumn = (columnTree.getType() == CliParser.FUNCTION_CALL)
                                  ? convertValueByFunction(columnTree, null, null).array()
                                  : columnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 0), columnFamily);

            colParent = new ColumnParent(columnFamily).setSuper_column(superColumn);
        }
View Full Code Here

            throws TException, InvalidRequestException, UnavailableException, TimedOutException
    {
        if (!CliMain.isConnected() || !hasKeySpace())
            return;

        Tree columnFamilySpec = statement.getChild(0);

        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
        CfDef cfDef = getCfDef(columnFamily);

        ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1));
        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

        byte[] superColumnName = null;
        byte[] columnName = null;
        boolean isSuper = cfDef.column_type.equals("Super");

        if ((columnSpecCnt < 0) || (columnSpecCnt > 2))
        {
            sessionState.out.println("Invalid row, super column, or column specification.");
            return;
        }

        long startTime = System.nanoTime();

        Tree columnTree = (columnSpecCnt >= 1)
                           ? columnFamilySpec.getChild(2)
                           : null;

        Tree subColumnTree = (columnSpecCnt == 2)
                              ? columnFamilySpec.getChild(3)
                              : null;

        if (columnSpecCnt == 1)
        {
            assert columnTree != null;

            byte[] columnNameBytes = (columnTree.getType() == CliParser.FUNCTION_CALL)
                                      ? convertValueByFunction(columnTree, null, null).array()
                                      : columnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 0), cfDef);


            if (isSuper)
                superColumnName = columnNameBytes;
            else
                columnName = columnNameBytes;
        }
        else if (columnSpecCnt == 2)
        {
            assert columnTree != null;
            assert subColumnTree != null;

            // table.cf['key']['column']['column']
            superColumnName = (columnTree.getType() == CliParser.FUNCTION_CALL)
                                      ? convertValueByFunction(columnTree, null, null).array()
                                      : columnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 0), cfDef);

            columnName = (subColumnTree.getType() == CliParser.FUNCTION_CALL)
                                         ? convertValueByFunction(subColumnTree, null, null).array()
                                         : subColumnNameAsByteArray(CliCompiler.getColumn(columnFamilySpec, 1), cfDef);
        }

        ColumnPath path = new ColumnPath(columnFamily);
View Full Code Here

            throws TException, NotFoundException, InvalidRequestException, UnavailableException, TimedOutException, IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchFieldException
    {
        if (!CliMain.isConnected() || !hasKeySpace())
            return;
        long startTime = System.nanoTime();
        Tree columnFamilySpec = statement.getChild(0);
        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
        ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1));
        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
        CfDef cfDef = getCfDef(columnFamily);
        boolean isSuper = cfDef.column_type.equals("Super");

        byte[] superColumnName = null;
        ByteBuffer columnName;

        Tree typeTree = null;
        Tree limitTree = null;

        int limit = 1000000;

        if (statement.getChildCount() >= 2)
        {
            if (statement.getChild(1).getType() == CliParser.CONVERT_TO_TYPE)
            {
                typeTree = statement.getChild(1).getChild(0);
                if (statement.getChildCount() == 3)
                    limitTree = statement.getChild(2).getChild(0);
            }
            else
            {
                limitTree = statement.getChild(1).getChild(0);
            }
        }

        if (limitTree != null)
        {
            limit = Integer.parseInt(limitTree.getText());

            if (limit == 0)
            {
                throw new IllegalArgumentException("LIMIT should be greater than zero.");
            }
View Full Code Here

        long startTime = System.nanoTime();

        IndexClause clause = new IndexClause();
        String columnFamily = CliCompiler.getColumnFamily(statement, currentCfDefs());
        // ^(CONDITIONS ^(CONDITION $column $value) ...)
        Tree conditions = statement.getChild(1);

        // fetching column family definition
        CfDef columnFamilyDef = getCfDef(columnFamily);

        // fetching all columns
        SlicePredicate predicate = new SlicePredicate();
        SliceRange sliceRange = new SliceRange();
        sliceRange.setStart(new byte[0]).setFinish(new byte[0]);
        predicate.setSlice_range(sliceRange);

        for (int i = 0; i < conditions.getChildCount(); i++)
        {
            // ^(CONDITION operator $column $value)
            Tree condition = conditions.getChild(i);

            // =, >, >=, <, <=
            String operator = condition.getChild(0).getText();
            String columnNameString  = CliUtils.unescapeSQLString(condition.getChild(1).getText());
            // it could be a basic string or function call
            Tree valueTree = condition.getChild(2);

            try
            {
                ByteBuffer value;
                ByteBuffer columnName = columnNameAsBytes(columnNameString, columnFamily);

                if (valueTree.getType() == CliParser.FUNCTION_CALL)
                {
                    value = convertValueByFunction(valueTree, columnFamilyDef, columnName);
                }
                else
                {
                    String valueString = CliUtils.unescapeSQLString(valueTree.getText());
                    value = columnValueAsBytes(columnName, columnFamily, valueString);
                }

                // index operator from string
                IndexOperator idxOperator = CliUtils.getIndexOperator(operator);
                // adding new index expression into index clause
                clause.addToExpressions(new IndexExpression(columnName, idxOperator, value));
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
        }

        List<KeySlice> slices;
        clause.setStart_key(new byte[] {});

        // when we have ^(NODE_LIMIT Integer)
        if (statement.getChildCount() == 3)
        {
            Tree limitNode = statement.getChild(2);
            int limitValue = Integer.parseInt(limitNode.getChild(0).getText());

            if (limitValue == 0)
            {
                throw new IllegalArgumentException("LIMIT should be greater than zero.");
            }
View Full Code Here

        if (!CliMain.isConnected() || !hasKeySpace())
            return;

        long startTime = System.nanoTime();
        // ^(NODE_COLUMN_ACCESS <cf> <key> <column>)
        Tree columnFamilySpec = statement.getChild(0);
        Tree keyTree = columnFamilySpec.getChild(1); // could be a function or regular text

        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
        CfDef cfDef = getCfDef(columnFamily);
        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
        String value = CliUtils.unescapeSQLString(statement.getChild(1).getText());
        Tree valueTree = statement.getChild(1);

        byte[] superColumnName = null;
        ByteBuffer columnName;

        // table.cf['key']
        if (columnSpecCnt == 0)
        {
            sessionState.err.println("No cell name specified, (type 'help;' or '?' for help on syntax).");
            return;
        }
        // table.cf['key']['column'] = 'value'
        else if (columnSpecCnt == 1)
        {
            // get the column name
            if (cfDef.column_type.equals("Super"))
            {
                sessionState.out.println("Column family " + columnFamily + " may only contain SuperColumns");
                return;
            }
            columnName = getColumnName(columnFamily, columnFamilySpec.getChild(2));
        }
        // table.cf['key']['super_column']['column'] = 'value'
        else
        {
            assert (columnSpecCnt == 2) : "serious parsing error (this is a bug).";

            superColumnName = getColumnName(columnFamily, columnFamilySpec.getChild(2)).array();
            columnName = getSubColumnName(columnFamily, columnFamilySpec.getChild(3));
        }

        ByteBuffer columnValueInBytes;

        switch (valueTree.getType())
        {
        case CliParser.FUNCTION_CALL:
            columnValueInBytes = convertValueByFunction(valueTree, cfDef, columnName, true);
            break;
        default:
View Full Code Here

            throws TException, NotFoundException, InvalidRequestException, UnavailableException, TimedOutException, IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchFieldException
    {
        if (!CliMain.isConnected() || !hasKeySpace())
            return;

        Tree columnFamilySpec = statement.getChild(0);

        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, currentCfDefs());
        ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1));
        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

        byte[] superColumnName = null;
        ByteBuffer columnName;

        // table.cf['key']['column'] -- incr standard
        if (columnSpecCnt == 1)
        {
            columnName = getColumnName(columnFamily, columnFamilySpec.getChild(2));
        }
        // table.cf['key']['column']['column'] -- incr super
        else if (columnSpecCnt == 2)
        {
            superColumnName = getColumnName(columnFamily, columnFamilySpec.getChild(2)).array();
            columnName = getSubColumnName(columnFamily, columnFamilySpec.getChild(3));
        }
        // The parser groks an arbitrary number of these so it is possible to get here.
        else
        {
            sessionState.out.println("Invalid row, super column, or column specification.");
View Full Code Here

                break;
            case GC_GRACE:
                cfDef.setGc_grace_seconds(Integer.parseInt(mValue));
                break;
            case COLUMN_METADATA:
                Tree arrayOfMetaAttributes = statement.getChild(i + 1);
                if (!arrayOfMetaAttributes.getText().equals("ARRAY"))
                    throw new RuntimeException("'column_metadata' format - [{ k:v, k:v, ..}, { ... }, ...]");
                cfDef.setColumn_metadata(getCFColumnMetaFromTree(cfDef, arrayOfMetaAttributes));
                break;
            case MEMTABLE_OPERATIONS:
                break;
View Full Code Here

TOP

Related Classes of org.antlr.runtime.tree.Tree

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.