Sha256: cb53bc14c1b4a92da4c77ed348ab2a0fd5a8f2262e05d4ee3cfe0679b95683cf

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

grammar SQLCreateTable
  include SQLRowSupport
  include SQLDataTypes

  rule create_table
    "CREATE" SPACES "TABLE" SPACES 
    table_name SPACES OPEN_PARENS columns_and_datatypes CLOSE_PARENS
    optional_engine {
      def eval
        options = {
          :columns    => columns_and_datatypes.eval,
          :table_name => table_name.eval
        }
        
        options
      end
      def query_type
        :create_table
      end
      def tree
        values = eval
        {
          :table => values[:table_name],
          :columns => values[:columns]
        }
      end
    }
  end

  rule columns_and_datatypes
    column_with_datatype COMMA columns_and_datatypes {
      def eval
        all = column_with_datatype.eval + columns_and_datatypes.eval
        all.flatten!
        all
      end
    }
    /
    column_with_datatype
  end

  rule column_with_datatype
    optional_spaces column_name SPACES datatype optional_column_features? optional_spaces {
      def eval
        [column_name.eval]
      end
    }
  end
  
  rule optional_column_features
    optional_column_feature optional_column_feature
    /
    optional_column_feature
  end
  
  rule optional_column_feature
    optional_primary_key /
    optional_auto_increment /
    optional_default /
    optional_not_null
  end
  
  rule optional_primary_key
    SPACES "PRIMARY" SPACES "KEY"
    /
    SPACES "primary" SPACES "key"
  end
  
  rule optional_default
    SPACES "DEFAULT" SPACES (quoted_string / NULL_KEYWORD / MINUS_OR_DIGIT+)
    /
    SPACES "default" SPACES (quoted_string / NULL_KEYWORD / MINUS_OR_DIGIT+)
  end
  
  rule optional_auto_increment
    SPACES "AUTO_INCREMENT"
    /
    SPACES "auto_increment"
  end
  
  rule optional_not_null
    SPACES (NOT_KEYWORD SPACES)? NULL_KEYWORD
  end
  
  rule optional_engine
    SPACES "ENGINE=InnoDB"
    /
    EMPTY_STRING
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hipster_sql_to_hbase-0.3.1 lib/sql_parser/sql_create_table.treetop
hipster_sql_to_hbase-0.3.0 lib/sql_parser/sql_create_table.treetop
hipster_sql_to_hbase-0.2.2 lib/sql_parser/sql_create_table.treetop