> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# aggregate_group_by

<div className="kinetica-pydoc">
  <div className="dl py method">
    <div className="dt sig sig-object py" id="gpudb.GPUdb.aggregate_group_by"> <span className="sig-name descname"><span className="pre">aggregate\_group\_by</span></span><span className="sig-paren">(</span><span className="em sig-param"><span className="n"><span className="pre">table\_name</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">None</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">column\_names</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">None</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">offset</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">0</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">limit</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">-9999</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">encoding</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">'binary'</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">options</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">{"{"}{"}"}</span></span></span><span className="sig-paren">)</span><a href="https://github.com/kineticadb/kinetica-api-python/blob/master/gpudb/gpudb.py#L15897"><span className="viewcode-link"><span className="pre">\[source]</span></span></a></div>

    <div className="dd">
      <p>Calculates unique combinations (groups) of values for the given columns in a given table or view and computes aggregates on each unique combination. This is somewhat analogous to an SQL-style SELECT…GROUP BY.</p>
      <p>For aggregation details and examples, see <a className="reference external" href="/content/concepts/aggregation/">Aggregation</a>. For limitations, see <a className="reference external" href="/content/concepts/aggregation/#limitations">Aggregation Limitations</a>.</p>
      <p>Any column(s) can be grouped on, and all column types except unrestricted-length strings may be used for computing applicable aggregates.</p>
      <p>The results can be paged via the input parameter <span className="em">offset</span> and input parameter <span className="em">limit</span> parameters. For example, to get 10 groups with the largest counts the inputs would be: limit=10, options={"{"}“sort\_order”:”descending”, “sort\_by”:”value”{"}"}.</p>
      <p>Input parameter <span className="em">options</span> can be used to customize behavior of this call e.g. filtering or sorting the results.</p>
      <p>To group by columns ‘x’ and ‘y’ and compute the number of objects within each group, use: column\_names=\[‘x’,’y’,’count(\*)’].</p>
      <p>To also compute the sum of ‘z’ over each group, use: column\_names=\[‘x’,’y’,’count(\*)’,’sum(z)’].</p>
      <p>Available <a className="reference external" href="/content/concepts/expressions/#aggregate-expressions">aggregation functions</a> are: count(\*), sum, min, max, avg, mean, stddev, stddev\_pop, stddev\_samp, var, var\_pop, var\_samp, arg\_min, arg\_max and count\_distinct.</p>
      <p>Available grouping functions are <a className="reference external" href="/content/concepts/rollup/">Rollup</a>, <a className="reference external" href="/content/concepts/cube/">Cube</a>, and <a className="reference external" href="/content/concepts/grouping_sets/">Grouping Sets</a></p>
      <p>This service also provides support for <a className="reference external" href="/content/concepts/pivot/">Pivot</a> operations.</p>
      <p>Filtering on aggregates is supported via expressions using <a className="reference external" href="/content/concepts/expressions/#aggregate-expressions">aggregation functions</a> supplied to <span className="em">having</span>.</p>
      <p>The response is returned as a dynamic schema. For details see: <a className="reference external" href="/content/api/concepts/#dynamic-schemas">dynamic schemas documentation</a>.</p>
      <p>If a <span className="em">result\_table</span> name is specified in the input parameter <span className="em">options</span>, the results are stored in a new table with that name–no results are returned in the response. Both the table name and resulting column names must adhere to <a className="reference external" href="/content/concepts/tables/#table">standard naming conventions</a>; column/aggregation expressions will need to be aliased. If the source table’s <a className="reference external" href="/content/concepts/tables/#shard-keys">shard key</a> is used as the grouping column(s) and all result records are selected (input parameter <span className="em">offset</span> is 0 and input parameter <span className="em">limit</span> is -9999), the result table will be sharded, in all other cases it will be replicated. Sorting will properly function only if the result table is replicated or if there is only one processing node and should not be relied upon in other cases. Not available when any of the values of input parameter <span className="em">column\_names</span> is an unrestricted-length string.</p>
      <p><strong>Parameters</strong></p>

      <div className="blockquote">
        <div>
          <div className="dl">
            <div className="dt">table\_name (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Name of an existing table or view on which the operation will be performed, in \[schema\_name.]table\_name format, using standard <a className="reference external" href="/content/concepts/tables/#table-name-resolution">name resolution rules</a>.</p>
            </div>

            <div className="dt">column\_names (<span className="em">list of str</span>) –</div>

            <div className="dd">
              <p>List of one or more column names, expressions, and aggregate expressions. The user can provide a single element (which will be automatically promoted to a list internally) or a list.</p>
            </div>

            <div className="dt">offset (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>A positive integer indicating the number of initial results to skip (this can be useful for paging through the results). The default value is 0. The minimum allowed value is 0. The maximum allowed value is MAX\_INT.</p>
            </div>

            <div className="dt">limit (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>A positive integer indicating the maximum number of results to be returned, or END\_OF\_SET (-9999) to indicate that the maximum number of results allowed by the server should be returned. The number of records returned will never exceed the server’s own limit, defined by the <a className="reference external" href="/content/config/#config-main-general">max\_get\_records\_size</a> parameter in the server configuration. Use output parameter <span className="em">has\_more\_records</span> to see if more records exist in the result to be fetched, and input parameter <span className="em">offset</span> and input parameter <span className="em">limit</span> to request subsequent pages of results. The default value is -9999.</p>
            </div>

            <div className="dt">encoding (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Specifies the encoding for returned records. Allowed values are:</p>

              <ul className="simple">
                <li>
                  <p><strong>binary</strong> – Indicates that the returned records should be binary encoded.</p>
                </li>

                <li>
                  <p><strong>json</strong> – Indicates that the returned records should be JSON-encoded.</p>
                </li>
              </ul>

              <p>The default value is ‘binary’.</p>
            </div>

            <div className="dt">options (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Optional parameters. Allowed keys are:</p>

              <ul>
                <li>
                  <p><strong>create\_temp\_table</strong> – If <span className="em">true</span>, a unique temporary table name will be generated in the sys\_temp schema and used in place of <span className="em">result\_table</span>. If <span className="em">result\_table\_persist</span> is <span className="em">false</span> (or unspecified), then this is always allowed even if the caller does not have permission to create tables. The generated name is returned in <span className="em">qualified\_result\_table\_name</span>. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>collection\_name</strong> – \[DEPRECATED–please specify the containing schema as part of <span className="em">result\_table</span> and use <a className="reference internal" href="#gpudb.GPUdb.create_schema" title="gpudb.GPUdb.create_schema"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdb.create\_schema()</span></code></a> to create the schema if non-existent] Name of a schema which is to contain the table specified in <span className="em">result\_table</span>. If the schema provided is non-existent, it will be automatically created.</p>
                </li>

                <li>
                  <p><strong>expression</strong> – Filter expression to apply to the table prior to computing the aggregate group by.</p>
                </li>

                <li>
                  <p><strong>pipelined\_expression\_evaluation</strong> – Evaluate the group-by during last JoinedSet filter plan step. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>having</strong> – Filter expression to apply to the aggregated results.</p>
                </li>

                <li>
                  <p><strong>sort\_order</strong> – \[DEPRECATED–use order\_by instead] String indicating how the returned values should be sorted - ascending or descending. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>ascending</strong> – Indicates that the returned values should be sorted in ascending order.</p>
                    </li>

                    <li>
                      <p><strong>descending</strong> – Indicates that the returned values should be sorted in descending order.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘ascending’.</p>
                </li>

                <li>
                  <p><strong>sort\_by</strong> – \[DEPRECATED–use order\_by instead] String determining how the results are sorted. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>key</strong> – Indicates that the returned values should be sorted by key, which corresponds to the grouping columns. If you have multiple grouping columns (and are sorting by key), it will first sort the first grouping column, then the second grouping column, etc.</p>
                    </li>

                    <li>
                      <p><strong>value</strong> – Indicates that the returned values should be sorted by value, which corresponds to the aggregates. If you have multiple aggregates (and are sorting by value), it will first sort by the first aggregate, then the second aggregate, etc.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘value’.</p>
                </li>

                <li>
                  <p><strong>order\_by</strong> – Comma-separated list of the columns to be sorted by as well as the sort direction, e.g., ‘timestamp asc, x desc’. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>strategy\_definition</strong> – The <a className="reference external" href="/content/rm/concepts/#tier-strategies">tier strategy</a> for the table and its columns.</p>
                </li>

                <li>
                  <p><strong>compression\_codec</strong> – The default <a className="reference external" href="/content/concepts/column_compression/">compression codec</a> for the result table’s columns.</p>
                </li>

                <li>
                  <p><strong>result\_table</strong> – The name of a table used to store the results, in \[schema\_name.]table\_name format, using standard <a className="reference external" href="/content/concepts/tables/#table-name-resolution">name resolution rules</a> and meeting <a className="reference external" href="/content/concepts/tables/#table-naming-criteria">table naming criteria</a>. Column names (group-by and aggregate fields) need to be given aliases e.g. \[“FChar256 as fchar256”, “sum(FDouble) as sfd”]. If present, no results are returned in the response. This option is not available if one of the grouping attributes is an unrestricted string (i.e.; not charN) type.</p>
                </li>

                <li>
                  <p><strong>result\_table\_persist</strong> – If <span className="em">true</span>, then the result table specified in <span className="em">result\_table</span> will be persisted and will not expire unless a <span className="em">ttl</span> is specified. If <span className="em">false</span>, then the result table will be an in-memory table and will expire unless a <span className="em">ttl</span> is specified otherwise. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>result\_table\_force\_replicated</strong> – Force the result table to be replicated (ignores any sharding). Must be used in combination with the <span className="em">result\_table</span> option. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>result\_table\_generate\_pk</strong> – If <span className="em">true</span> then set a primary key for the result table. Must be used in combination with the <span className="em">result\_table</span> option. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>result\_table\_generate\_soft\_pk</strong> – If <span className="em">true</span> then set a soft primary key for the result table. Must be used in combination with the <span className="em">result\_table</span> option. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>ttl</strong> – Sets the <a className="reference external" href="/content/concepts/ttl/">TTL</a> of the table specified in <span className="em">result\_table</span>.</p>
                </li>

                <li>
                  <p><strong>chunk\_size</strong> – Indicates the number of records per chunk to be used for the result table. Must be used in combination with the <span className="em">result\_table</span> option.</p>
                </li>

                <li>
                  <p><strong>chunk\_column\_max\_memory</strong> – Indicates the target maximum data size for each column in a chunk to be used for the result table. Must be used in combination with the <span className="em">result\_table</span> option.</p>
                </li>

                <li>
                  <p><strong>chunk\_max\_memory</strong> – Indicates the target maximum data size for all columns in a chunk to be used for the result table. Must be used in combination with the <span className="em">result\_table</span> option.</p>
                </li>

                <li>
                  <p><strong>create\_indexes</strong> – Comma-separated list of columns on which to create indexes on the result table. Must be used in combination with the <span className="em">result\_table</span> option.</p>
                </li>

                <li>
                  <p><strong>partition\_type</strong> – <a className="reference external" href="/content/concepts/tables/#partitioning">Partitioning</a> scheme to use for the result table. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>RANGE</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-range">range partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>INTERVAL</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-interval">interval partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>LIST</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>HASH</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-hash">hash partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>SERIES</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-series">series partitioning</a>.</p>
                    </li>
                  </ul>
                </li>

                <li>
                  <p><strong>partition\_keys</strong> – Comma-separated list of partition keys, which are the columns or column expressions by which records will be assigned to partitions defined by <span className="em">partition\_definitions</span>.</p>
                </li>

                <li>
                  <p><strong>partition\_definitions</strong> – Comma-separated list of partition definitions, whose format depends on the choice of <span className="em">partition\_type</span>. See <a className="reference external" href="/content/concepts/tables/#partitioning-by-range">range partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-interval">interval partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-hash">hash partitioning</a>, or <a className="reference external" href="/content/concepts/tables/#partitioning-by-series">series partitioning</a> for example formats.</p>
                </li>

                <li>
                  <p><strong>is\_automatic\_partition</strong> – If <span className="em">true</span>, a new partition will be created for values which don’t fall into an existing partition. Currently only supported for <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitions</a>. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>view\_id</strong> – ID of view of which the result table will be a member. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>pivot</strong> – Pivot column.</p>
                </li>

                <li>
                  <p><strong>pivot\_values</strong> – Comma-separated list of the values in the <span className="em">pivot</span> column. The list provided will become the column header prefixes in the output.</p>
                </li>

                <li>
                  <p><strong>grouping\_sets</strong> – Customize the grouping attribute sets to compute the aggregates. These sets can include ROLLUP or CUBE operators. The attribute sets should be enclosed in parentheses and can include composite attributes. All attributes specified in the grouping sets must present in the group-by attributes.</p>
                </li>

                <li>
                  <p><strong>rollup</strong> – This option is used to specify the multilevel aggregates.</p>
                </li>

                <li>
                  <p><strong>cube</strong> – This option is used to specify the multidimensional aggregates.</p>
                </li>

                <li>
                  <p><strong>shard\_key</strong> – Comma-separated list of the columns to be sharded on; e.g. ‘column1, column2’. The columns specified must be present in input parameter <span className="em">column\_names</span>. If any alias is given for any column name, the alias must be used, rather than the original column name. The default value is ‘’.</p>
                </li>
              </ul>

              <p>The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>
          </div>
        </div>
      </div>

      <p><strong>Returns</strong></p>

      <div className="blockquote">
        <div>
          <p>A dict with the following entries–</p>

          <div className="dl">
            <div className="dt">response\_schema\_str (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Avro schema of output parameter <span className="em">binary\_encoded\_response</span> or output parameter <span className="em">json\_encoded\_response</span>.</p>
            </div>

            <div className="dt">binary\_encoded\_response (<span className="em">bytes</span>) –</div>

            <div className="dd">
              <p>Avro binary encoded response.</p>
            </div>

            <div className="dt">json\_encoded\_response (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Avro JSON encoded response.</p>
            </div>

            <div className="dt">total\_number\_of\_records (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>Total/Filtered number of records. This may be an over-estimate if a limit was applied and there are additional records (i.e., when output parameter <span className="em">has\_more\_records</span> is true).</p>
            </div>

            <div className="dt">has\_more\_records (<span className="em">bool</span>) –</div>

            <div className="dd">
              <p>Too many records. Returned a partial set.</p>
            </div>

            <div className="dt">info (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Additional information. Allowed keys are:</p>

              <ul className="simple">
                <li>
                  <p><strong>qualified\_result\_table\_name</strong> – The fully qualified name of the table (i.e. including the schema) used to store the results.</p>
                </li>
              </ul>

              <p>The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>

            <div className="dt">record\_type (<code className="xref py py-class docutils literal notranslate"><span className="pre">RecordType</span></code> or None) –</div>

            <div className="dd">
              <p>A <code className="xref py py-class docutils literal notranslate"><span className="pre">RecordType</span></code> object using which the user can decode the binary data by using <a className="reference internal" href="/content/api/python/source/gpudbrecord#gpudb.GPUdbRecord.decode_binary_data" title="gpudb.GPUdbRecord.decode_binary_data"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdbRecord.decode\_binary\_data()</span></code></a>. If JSON encoding is used, then None.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
