public static VoltTable tableFromShorthand(String schema) {

        String name = "T";
        VoltTable.ColumnInfo[] columns = null;

        // get a name
        Matcher nameMatcher = m_namePattern.matcher(schema);
        if (nameMatcher.find()) {
            name = nameMatcher.group().trim();
        }

        // get the column schema
        Matcher columnDataMatcher = m_columnsPattern.matcher(schema);
        if (!columnDataMatcher.find()) {
            throw new IllegalArgumentException("No column data found in shorthand");
        }
        String[] columnData = columnDataMatcher.group().trim().split("\\s*,\\s*");
        int columnCount = columnData.length;

        columns = new VoltTable.ColumnInfo[columnCount];

        for (int i = 0; i < columnCount; i++) {
            columns[i] = parseColumnShorthand(columnData[i], i);
        }

        // get the pkey
        Matcher pkeyMatcher = m_pkeyPattern.matcher(schema);
        int[] pkeyIndexes = new int[0]; // default no pkey
        if (pkeyMatcher.find()) {
            String[] pkeyColData = pkeyMatcher.group().trim().split("\\s*,\\s*");
            pkeyIndexes = new int[pkeyColData.length];
            for (int pkeyIndex = 0; pkeyIndex < pkeyColData.length; pkeyIndex++) {
                String pkeyCol = pkeyColData[pkeyIndex];
                // numeric means index of column
                if (Character.isDigit(pkeyCol.charAt(0))) {
                    int colIndex = Integer.parseInt(pkeyCol);
                    pkeyIndexes[pkeyIndex] = colIndex;
                }
                else {
                    for (int colIndex = 0; colIndex < columnCount; colIndex++) {
                        if (columns[colIndex].name.equals(pkeyCol)) {
                            pkeyIndexes[pkeyIndex] = colIndex;
                            break;
                        }
                    }
                }
            }
        }

        // get any partitioning
        Matcher partitionMatcher = m_partitionPattern.matcher(schema);
        int partitionColumnIndex = -1; // default to replicated
        if (partitionMatcher.find()) {
            String partitionColStr = partitionMatcher.group().trim();
            // numeric means index of column
            if (Character.isDigit(partitionColStr.charAt(0))) {
                partitionColumnIndex = Integer.parseInt(partitionColStr);
            }
            else {
                for (int colIndex = 0; colIndex < columnCount; colIndex++) {
                    if (columns[colIndex].name.equals(partitionColStr)) {
                        partitionColumnIndex = colIndex;
                        break;
                    }
                }
            }
            assert(partitionColumnIndex != -1) : "Regex match here means there is a partitioning column";
        }

        VoltTable table = new VoltTable(
                new VoltTable.ExtraMetadata(name, partitionColumnIndex, pkeyIndexes, columns),
                columns,
                columns.length);
        return table;
    }
public static VoltTable tableFromShorthand ( String schema ) { String name = "T" ; VoltTable . ColumnInfo [ ] columns = null ; Matcher nameMatcher = m_namePattern . matcher ( schema ) ; if ( nameMatcher . find ( ) ) { name = nameMatcher . group ( ) . trim ( ) ; } Matcher columnDataMatcher = m_columnsPattern . matcher ( schema ) ; if ( ! columnDataMatcher . find ( ) ) { throw new IllegalArgumentException ( "No column data found in shorthand" ) ; } String [ ] columnData = columnDataMatcher . group ( ) . trim ( ) . split ( "\\s*,\\s*" ) ; int columnCount = columnData . length ; columns = new VoltTable . ColumnInfo [ columnCount ] ; for ( int i = 0 ; i < columnCount ; i ++ ) { columns [ i ] = parseColumnShorthand ( columnData [ i ] , i ) ; } Matcher pkeyMatcher = m_pkeyPattern . matcher ( schema ) ; int [ ] pkeyIndexes = new int [ 0 ] ; if ( pkeyMatcher . find ( ) ) { String [ ] pkeyColData = pkeyMatcher . group ( ) . trim ( ) . split ( "\\s*,\\s*" ) ; pkeyIndexes = new int [ pkeyColData . length ] ; for ( int pkeyIndex = 0 ; pkeyIndex < pkeyColData . length ; pkeyIndex ++ ) { String pkeyCol = pkeyColData [ pkeyIndex ] ; if ( Character . isDigit ( pkeyCol . charAt ( 0 ) ) ) { int colIndex = Integer . parseInt ( pkeyCol ) ; pkeyIndexes [ pkeyIndex ] = colIndex ; } else { for ( int colIndex = 0 ; colIndex < columnCount ; colIndex ++ ) { if ( columns [ colIndex ] . name . equals ( pkeyCol ) ) { pkeyIndexes [ pkeyIndex ] = colIndex ; break ; } } } } } Matcher partitionMatcher = m_partitionPattern . matcher ( schema ) ; int partitionColumnIndex = - 1 ; if ( partitionMatcher . find ( ) ) { String partitionColStr = partitionMatcher . group ( ) . trim ( ) ; if ( Character . isDigit ( partitionColStr . charAt ( 0 ) ) ) { partitionColumnIndex = Integer . parseInt ( partitionColStr ) ; } else { for ( int colIndex = 0 ; colIndex < columnCount ; colIndex ++ ) { if ( columns [ colIndex ] . name . equals ( partitionColStr ) ) { partitionColumnIndex = colIndex ; break ; } } } assert ( partitionColumnIndex != - 1 ) : "Regex match here means there is a partitioning column" ; } VoltTable table = new VoltTable ( new VoltTable . ExtraMetadata ( name , partitionColumnIndex , pkeyIndexes , columns ) , columns , columns . length ) ; return table ; }
Parse the shorthand according to the syntax as described
in the class comment.