Sha256: a1b9882a724369b843ee77db201746c015ae4985ccade64032f6b16c88c513af

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

grammar SQLShowTables
  include SQLPrimitives
  include SQLRowSupport
  include SQLWhereCondition

  rule show_tables
    "SHOW" SPACES optional_full 
    tables_or_fields 
    optional_from_table
    optional_like_or_where {
      def query_type
        :show
      end
      
      def tree
        like_where = optional_like_or_where.eval
        {
          :show => tables_or_fields.eval,
          :full => optional_full.eval,
          :from => optional_from_table.eval,
          :like => like_where[:like],
          :where => like_where[:where]
        }
      end
    }
  end
  
  rule tables_or_fields
    "TABLES" {
      def eval
        "tables"
      end
    }
    /
    "FIELDS" {
      def eval
        "fields"
      end
    }
    /
    "KEYS" {
      def eval
        "keys"
      end
    }
  end
  
  rule optional_like_or_where
    EMPTY_STRING like_pattern {
      def eval
        {
          :like => like_pattern.eval,
          :where => nil
        }
      end
    }
    / 
    EMPTY_STRING where_tree {
      def eval
        {
          :like => nil,
          :where => where_tree.eval
        }
      end
    }
    /
    EMPTY_STRING {
      def eval
        {
          :like => nil,
          :where => nil
        }
      end
    }
  end

  rule optional_full
    "FULL" SPACES {
      def eval
        true
      end
    }
    /
    EMPTY_STRING {
      def eval
        false
      end
    }
  end

  rule optional_from_table
    SPACES "FROM" SPACES table_name {
      def eval
        table_name.eval
      end
    }
    /
    EMPTY_STRING {
      def eval
        nil
      end
    }
  end

  rule like_pattern
    SPACES "LIKE" SPACES single_quoted_string {
      def eval
        single_quoted_string.eval
      end
    }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hipster_sql_to_hbase-0.3.29 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.3.20 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.3.12 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.3.2 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.3.1 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.3.0 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.2.2 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.2.0 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.1.85 lib/sql_parser/sql_show_tables.treetop
hipster_sql_to_hbase-0.1.8 lib/sql_parser/sql_show_tables.treetop