Ejemplo n.º 1
0
    def _get_sample_partition_query(self,
                                    database,
                                    table,
                                    column='*',
                                    limit=100):
        max_parts = QUERY_PARTITIONS_LIMIT.get()
        partitions = self.get_partitions(database,
                                         table,
                                         partition_spec=None,
                                         max_parts=max_parts)

        if partitions and max_parts:
            # Need to reformat partition specs for where clause syntax
            partition_specs = [
                part.partition_spec.replace(',', ' AND ')
                for part in partitions
            ]
            partition_filters = ' OR '.join([
                '(%s)' % partition_spec for partition_spec in partition_specs
            ])
            partition_clause = 'WHERE %s' % partition_filters
        else:
            partition_clause = ''

        return "SELECT %(column)s FROM `%(database)s`.`%(table)s` %(partition_clause)s LIMIT %(limit)s" % \
          {'column': column, 'database': database, 'table': table.name, 'partition_clause': partition_clause, 'limit': limit}
Ejemplo n.º 2
0
Archivo: dbms.py Proyecto: gorden2/hue
  def _get_sample_partition_query(self, database, table, column='*', limit=100):
    max_parts = QUERY_PARTITIONS_LIMIT.get()
    partitions = self.get_partitions(database, table, partition_spec=None, max_parts=max_parts)

    if partitions and max_parts:
      # Need to reformat partition specs for where clause syntax
      partition_specs = [part.partition_spec.replace(',', ' AND ') for part in partitions]
      partition_filters = ' OR '.join(['(%s)' % partition_spec for partition_spec in partition_specs])
      partition_clause = 'WHERE %s' % partition_filters
    else:
      partition_clause = ''

    return "SELECT %(column)s FROM `%(database)s`.`%(table)s` %(partition_clause)s LIMIT %(limit)s" % \
      {'column': column, 'database': database, 'table': table.name, 'partition_clause': partition_clause, 'limit': limit}
Ejemplo n.º 3
0
Archivo: dbms.py Proyecto: fnerdwq/hue
    def _get_sample_partition_query(self, database, table, limit):
        max_parts = QUERY_PARTITIONS_LIMIT.get()
        partitions = self.get_partitions(database, table, partition_spec=None, max_parts=max_parts)

        if partitions and max_parts:
            # Need to reformat partition specs for where clause syntax
            partition_specs = [part.partition_spec.replace(",", " AND ") for part in partitions]
            partition_filters = " OR ".join(["(%s)" % partition_spec for partition_spec in partition_specs])
            partition_clause = "WHERE %s" % partition_filters
        else:
            partition_clause = ""

        return "SELECT * FROM `%(database)s`.`%(table)s` %(partition_clause)s LIMIT %(limit)s" % {
            "database": database,
            "table": table.name,
            "partition_clause": partition_clause,
            "limit": limit,
        }
Ejemplo n.º 4
0
  def _get_sample_partition_query(self, database, table, column='*', limit=100, operation=None):
    max_parts = QUERY_PARTITIONS_LIMIT.get()
    partitions = self.get_partitions(database, table, partition_spec=None, max_parts=max_parts)

    if partitions and max_parts:
      # Need to reformat partition specs for where clause syntax
      partition_specs = [part.partition_spec.replace(',', ' AND ') for part in partitions]
      partition_filters = ' OR '.join(['(%s)' % partition_spec for partition_spec in partition_specs])
      partition_clause = 'WHERE %s' % partition_filters
    else:
      partition_clause = ''

    if operation == 'distinct':
      prefix = 'SELECT DISTINCT %s' % column
    elif operation == 'max':
      prefix = 'SELECT max(%s)' % column
    elif operation == 'min':
      prefix = 'SELECT min(%s)' % column
    else:
      prefix = 'SELECT %s' % column

    return prefix + " FROM `%(database)s`.`%(table)s` %(partition_clause)s LIMIT %(limit)s" % \
      {'database': database, 'table': table.name, 'partition_clause': partition_clause, 'limit': limit}
Ejemplo n.º 5
0
Archivo: dbms.py Proyecto: cloudera/hue
  def _get_sample_partition_query(self, database, table, column='*', limit=100, operation=None):
    max_parts = QUERY_PARTITIONS_LIMIT.get()
    partitions = self.get_partitions(database, table, partition_spec=None, max_parts=max_parts)

    if partitions and max_parts:
      # Need to reformat partition specs for where clause syntax
      partition_specs = [part.partition_spec.replace(',', ' AND ') for part in partitions]
      partition_filters = ' OR '.join(['(%s)' % partition_spec for partition_spec in partition_specs])
      partition_clause = 'WHERE %s' % partition_filters
    else:
      partition_clause = ''

    if operation == 'distinct':
      prefix = 'SELECT DISTINCT %s' % column
    elif operation == 'max':
      prefix = 'SELECT max(%s)' % column
    elif operation == 'min':
      prefix = 'SELECT min(%s)' % column
    else:
      prefix = 'SELECT %s' % column

    return prefix + " FROM `%(database)s`.`%(table)s` %(partition_clause)s LIMIT %(limit)s" % \
      {'database': database, 'table': table.name, 'partition_clause': partition_clause, 'limit': limit}