LogoLogo
  • Welcome to e6data
  • Introduction to e6data
    • Concepts
    • Architecture
      • e6data in VPC Deployment Model
      • Connect to e6data serverless compute
  • Get Started
  • Sign Up
  • Setup
    • AWS Setup
      • In VPC Deployment (AWS)
        • Prerequisite Infrastructure
        • Infrastructure & Permissions for e6data
        • Setup Kubernetes Components
        • Setup using Terraform in AWS
          • Update a AWS Terraform for your Workspace
        • AWS PrivateLink and e6data
        • VPC Peering | e6data on AWS
      • Connect to e6data serverless compute (AWS)
        • Workspace Creation
        • Catalog Creation
          • Glue Metastore
          • Hive Metastore
          • Unity Catalog
        • Cluster Creation
    • GCP Setup
      • In VPC Deployment (GCP)
        • Prerequisite Infrastructure
        • Infrastructure & Permissions for e6data
        • Setup Kubernetes Components
        • Setup using Terraform in GCP
        • Update a GCP Terraform for your Workspace
      • Connect to e6data serverless compute (GCP)
    • Azure Setup
      • Prerequisite Infrastructure
      • Infrastructure & Permissions for e6data
      • Setup Kubernetes Components
      • Setup using Terraform in AZURE
        • Update a AZURE Terraform for your Workspace
  • Workspaces
    • Create Workspaces
    • Enable/Disable Workspaces
    • Update a Workspace
    • Delete a Workspace
  • Catalogs
    • Create Catalogs
      • Hive Metastore
        • Connect to a Hive Metastore
        • Edit a Hive Metastore Connection
        • Delete a Hive Metastore Connection
      • Glue Metastore
        • Connect to a Glue Metastore
        • Edit a Glue Metastore Connection
        • Delete a Glue Metastore Connection
      • Unity Catalog
        • Connect to Unity Catalog
        • Edit Unity Catalog
        • Delete Unity Catalog
      • Cross-account Catalog Access
        • Configure Cross-account Catalog to Access AWS Hive Metastore
        • Configure Cross-account Catalog to Access Unity Catalog
        • Configure Cross-account Catalog to Access AWS Glue
        • Configure Cross-account Catalog to Access GCP Hive Metastore
    • Manage Catalogs
    • Privileges
      • Access Control
      • Column Masking
      • Row Filter
  • Clusters
    • Edit & Delete Clusters
    • Suspend & Resume Clusters
    • Cluster Size
    • Load Based Sizing
    • Auto Suspension
    • Query Timeout
    • Monitoring
    • Connection Info
  • Pools
    • Delete Pools
  • Query Editor
    • Editor Pane
    • Results Pane
    • Schema Explorer
    • Data Preview
  • Notebook
    • Editor Pane
    • Results Pane
    • Schema Explorer
    • Data Preview
  • Query History
    • Query Count API
  • Connectivity
    • IP Sets
    • Endpoints
    • Cloud Resources
    • Network Firewall
  • Access Control
    • Users
    • Groups
    • Roles
      • Permissions
      • Policies
    • Single Sign-On (SSO)
      • AWS SSO
      • Okta
      • Microsoft My Apps-SSO
      • Icons for IdP
    • Service Accounts
    • Multi-Factor Authentication (Beta)
  • Usage and Cost Management
  • Audit Log
  • User Settings
    • Profile
    • Personal Access Tokens (PAT)
  • Advanced Features
    • Cross-Catalog & Cross-Schema Querying
  • Supported Data Types
  • SQL Command Reference
    • Query Syntax
      • General functions
    • Aggregate Functions
    • Mathematical Functions & Operators
      • Arithematic Operators
      • Rounding and Truncation Functions
      • Exponential and Root Functions
      • Trigonometric Functions
      • Logarithmic Functions
    • String Functions
    • Date-Time Functions
      • Constant Functions
      • Conversion Functions
      • Date Truncate Function
      • Addition and Subtraction Functions
      • Extraction Functions
      • Format Functions
      • Timezone Functions
    • Conditional Expressions
    • Conversion Functions
    • Window Functions
    • Comparison Operators & Functions
    • Logical Operators
    • Statistical Functions
    • Bitwise Functions
    • Array Functions
    • Regular Expression Functions
    • Generate Functions
    • Cardinality Estimation Functions
    • JSON Functions
    • Checksum Functions
    • Unload Function (Copy into)
    • Struct Functions
  • Equivalent Functions & Operators
  • Connectors & Drivers
    • DBeaver
    • DbVisualiser
    • Apache Superset
    • Jupyter Notebook
    • Tableau Cloud
    • Tableau Desktop
    • Power BI
    • Metabase
    • Zeppelin
    • Python Connector
      • Code Samples
    • JDBC Driver
      • Code Samples
      • API Support
    • Configure Cluster Ingress
      • ALB Ingress in Kubernetes
      • GCE Ingress in Kubernetes
      • Ingress-Nginx in Kubernetes
  • Security & Trust
    • Best Practices
      • AWS Best Practices
    • Features & Responsibilities Matrix
    • Data Protection Addendum(DPA)
  • Tutorials and Best Practices
    • How to configure HIVE metastore if you don't have one?
    • How-To Videos
  • Known Limitations
    • SQL Limitations
    • Other Limitations
    • Restart Triggers
    • Cloud Provider Limitations
  • Error Codes
    • General Errors
    • User Account Errors
    • Workspace Errors
    • Catalog Errors
    • Cluster Errors
    • Data Governance Errors
    • Query History Errors
    • Query Editor Errors
    • Pool Errors
    • Connectivity Errors
  • Terms & Condition
  • Privacy Policy
    • Cookie Policy
  • FAQs
    • Workspace Setup
    • Security
    • Catalog Privileges
  • Services Utilised for e6data Deployment
    • AWS supported regions
    • GCP supported regions
    • AZURE supported regions
  • Release Notes & Updates
    • 6th Sept 2024
    • 6th June 2024
    • 18th April 2024
    • 9th April 2024
    • 30th March 2024
    • 16th March 2024
    • 14th March 2024
    • 12th March 2024
    • 2nd March 2024
    • 10th February 2024
    • 3rd February 2024
    • 17th January 2024
    • 9th January 2024
    • 3rd January 2024
    • 18th December 2023
    • 12th December 2023
    • 9th December 2023
    • 4th December 2023
    • 27th November 2023
    • 8th September 2023
    • 4th September 2023
    • 26th August 2023
    • 21st August 2023
    • 19th July 2023
    • 23rd May 2023
    • 5th May 2023
    • 28th April 2023
    • 19th April 2023
    • 15th April 2023
    • 10th April 2023
    • 30th March 2023
Powered by GitBook
On this page
  • Ranking Functions
  • Value Functions
  • Window Frame Functions
  • Other Functions
  1. SQL Command Reference

Window Functions

This page contains window functions supported by e6data.

Ranking Functions

RANK()

Returns the rank of a value compared to all values in the partition. It will produce gaps in the ranking sequence and does not break ties.

rank() over(order by a)
rank() over(partition by a order by b)

DENSE_RANK()

Returns the rank of a value compared to all values in the partition. It will not produce gaps in the ranking sequence and does not break ties.

dense_rank() over(order by a)
dense_rank() over(partition by a order by b)

ROW_NUMBER()

Returns a unique, sequential number for each row, starting with 1, according to the ordering of rows within the window partition

row_number() over(order by a)
row_number() over(partition by a order by b)

NTILE( n )

Divides the rows for each window partition into n , where n is greater than 1 bucket, ranging from 1 to at most n

ntile(n) over(order by a)
ntile(n) over(partition by a order by b)
> select colA, ntile(10) over( order by colA desc) as ntile_val from table;

> select colB, ntile(10) over( partition by colB order by colc desc) as ntile_val from table;

Value Functions

FIRST_VALUE( <expr> )

Returns the first value of expr for a group of rows.

> SELECT first_value(col) over (order by colA desc) FROM table;

LAST_VALUE( <expr> )

Returns the last value of expr for a group of rows.

> SELECT last_value(col) over ( partition by colB order by colA desc) FROM table;

LEAD( <expr>, offset )

Returns data in a subsequent row in the same result set without joining the table to itself.

If the offset is null or larger than the window NULL is returned.

> select * from (
    select lead(count(colB),5) over (order by colA)
    from table)
  order by colA DESC;

LAG( <expr>, offset )

Returns data in a preceding row in the same result set without joining the table to itself.

If the offset is null or larger than the window NULL is returned.

> select * from (
    select lag(count(colB),5) over (order by colA)
    from table)
  order by colA DESC;

Window Frame Functions

Window Frame functions provide the ability to specify the upper and lower bounds of a window frame.

Note: e6data currently supports only SUM & COUNT functions in Window Frame functions

Syntax:

<function> ( <arguments> ) OVER ( PARTITION BY <expr1> ORDER BY <expr2> 
<frame_type> )
  • Cumulative Frames

rows between unbounded preceding and current row
rows between current row and unbounded following
  • Sliding Frames

rows between <num> { preceding | following } and <num> { preceding | following }
rows between unbounded preceding and <num> { preceding | following }
rows between <num> { preceding | following } and unbounded following
> select
    count(a) over (partition by b order by c rows between unbounded preceding and current row),
    count(a) over (partition by b order by c rows between 2 following and  unbounded following),
    count(a) over (partition by b order by c rows between 2 preceding and  2 following),
    sum(a)   over (partition by b order by c rows between unbounded preceding and current row),
    sum(a) over (partition by b order by c rows between 2 following and  unbounded following),
    sum(a) over (partition by b order by c rows between 2 preceding and  2 following)
  from table
  ;

Other Functions

COLLECT_LIST()

  • The collect_list function enables you to create an ordered list of values from a specified column within a group or window.

  • It is particularly useful when you need to gather and process multiple values associated with a particular grouping key or window frame.

Usage Examples:

  1. Aggregation Example: This query below aggregates values from the "value_column" and creates a list of those values for each unique "key_column" value.

SELECT key_column, collect_list(value_column) AS value_list
FROM table_name
GROUP BY key_column;
  1. Windowing Example: This query generates a list of values from the "value_column" within each window defined by the "partition_column." The values are ordered by the "order_column" within each window.

SELECT key_column, collect_list(value_column) OVER (PARTITION BY partition_column ORDER BY order_column) AS value_list
FROM table_name;

Limitations:

  1. Unsupported Complex Data Types: The collect_list function currently does not support complex data type columns as input. It is designed to work with simple data types such as integers, strings, or dates.

  2. Absence of Sorting Capability: The collect_list function does not allow for sorting operations, such as using the ORDER BY clause. The resulting list is generated based on the order of appearance of the values in the dataset, without the ability to explicitly control the ordering.

  3. Incompatibility with Distinct Operation: The collect_list function cannot be used in conjunction with the DISTINCT operation. It is intended to gather all values within a specified grouping or windowing context, without eliminating duplicates or applying distinctness.

PreviousConversion FunctionsNextComparison Operators & Functions

Last updated 9 months ago