Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Database
  • Getting started
    • Overview
    • Create databases
    • Examples of YQL queries
    • Examples of operations in the YDB CLI
    • Launch a test app
    • Document API
    • Developing in NodeJS through the Document API
  • Step-by-step instructions
    • Database management
    • How to connect to a database
    • Table management
    • Reading and writing data
    • Working with secondary indexes
  • Working with the SDK
  • Concepts
    • Overview
    • Data model and schema
    • Serverless and Dedicated operation modes
    • Data types
    • Transactions
    • Secondary indexes
    • Time to Live (TTL)
    • Terms and definitions
    • Quotas and limits
  • Access management
  • Pricing policy
    • Overview
    • Serverless mode
    • Dedicated mode
  • Recommendations
    • Schema design
    • Partitioning tables
    • Secondary indexes
    • Paginated output
    • Loading large data volumes
    • Using timeouts
  • YDB API and API reference
    • Database limits
    • Handling errors in the API
  • Amazon DynamoDB-compatible HTTP API
    • API reference
      • All methods
      • Actions
        • BatchGetItem
        • BatchWriteItem
        • CreateTable
        • DeleteItem
        • DeleteTable
        • DescribeTable
        • GetItem
        • ListTables
        • PutItem
        • Query
        • Scan
        • TransactGetItems
        • TransactWriteItems
        • UpdateItem
      • Common errors
  • YQL reference guide
    • Overview
    • Data types
      • Simple
      • Optional
      • Containers
      • Special
    • Syntax
      • Unsupported statements
      • For text representation of data types
      • Expressions
      • CREATE TABLE
      • DROP TABLE
      • INSERT INTO
      • UPSERT INTO
      • REPLACE INTO
      • UPDATE
      • DELETE
      • SELECT
      • GROUP BY
      • JOIN
      • FLATTEN
      • ACTION
      • DISCARD
      • PRAGMA
      • DECLARE
      • OVER, PARTITION BY, and WINDOW
    • Built-in functions
      • Basic
      • Aggregate
      • Window
      • For lists
      • For dictionaries
      • For JSON
      • For structures
      • For types
    • Preset user-defined functions
      • HyperScan
      • Pcre
      • Pire
      • Re2
      • String
      • Unicode
      • Datetime
      • Url
      • Ip
      • Digest
      • Math
      • Histogram
    • For text representation of data types
  • YQL tutorial
    • Overview
    • Creating a table
    • Adding data to a table
    • Selecting data from all columns
    • Selecting data from specific columns
    • Sorting and filtering
    • Data aggregation
    • Additional selection criteria
    • Joining tables by JOIN
    • Data insert and update by REPLACE
    • Data insert and update by UPSERT
    • Data insert by INSERT
    • Data update by UPDATE
    • Deleting data
    • Adding and deleting columns
    • Deleting a table
  • Maintenance
    • Backups
  • Diagnostics
    • System views
  • Questions and answers
    • General questions
    • Errors
    • YQL
    • All questions on the same page
  • Public materials
  1. YQL reference guide
  2. Built-in functions
  3. For dictionaries

Functions for dictionaries

  • DictCreate
  • DictItems
  • DictKeys
  • DictPayloads
  • DictLookup
  • DictContains
  • DictAggregate
  • SetIsDisjoint
  • SetIntersection
  • SetIncludes
  • SetUnion
  • SetDifference
  • SetSymmetricDifference

DictCreate

Construct an empty dictionary. Two arguments are passed: for a key and a value. Each argument specifies a string with the data type declaration or the type itself obtained using the applicable functions. There are no dictionaries with an unknown key or value type in YQL. As a key, you can use a primitive data type (except Yson and Json with an optional nullable flag), or their tuple with a length of at least two.

Documentation for type description format.

Examples

SELECT DictCreate(String, Tuple<String,Double?>);
SELECT DictCreate(Tuple<Int32?,String>, OptionalType(DataType("String")));

DictItems

Get the dictionary content as a list of tuples with key-value pairs (List<Tuplekey_type,value_type>).

Examples

SELECT DictItems(AsDict(AsTuple(1, AsList("foo", "bar"))));
-- [ ( 1, [ "foo", "bar" ] ) ]

DictKeys

Get a list of dictionary keys.

Examples

SELECT DictKeys(AsDict(AsTuple(1, AsList("foo", "bar"))));
-- [ 1 ]

DictPayloads

Get a list of dictionary values.

Examples

SELECT DictPayloads(AsDict(AsTuple(1, AsList("foo", "bar"))));
-- [ [ "foo", "bar" ] ]

DictLookup

Get a dictionary element by its key.

Examples

SELECT DictLookup(AsDict(
    AsTuple(1, AsList("foo", "bar")),
    AsTuple(2, AsList("bar", "baz"))
), 1);
-- [ "foo", "bar" ]

DictContains

Checking if an element in the dictionary using its key. Returns true or false.

Examples

SELECT DictContains(AsDict(
    AsTuple(1, AsList("foo", "bar")),
    AsTuple(2, AsList("bar", "baz"))
), 42);
-- false

DictAggregate

Apply aggregation factory to the passed dictionary where each value is a list. The factory is applied separately inside each key.
If the list is empty, the aggregation result is the same as for an empty table: 0 for the COUNT function and NULL for other functions.
If the list under a certain key is empty in the passed dictionary, such a key is removed from the result.
If the passed dictionary is optional and contains NULL, the result is also NULL.

Arguments:

  1. Dictionary.
  2. Aggregation factory.

Examples

SELECT DictAggregate(AsDict(
    AsTuple(1, AsList("foo", "bar")),
    AsTuple(2, AsList("baz", "qwe"))), 
    AGGREGATION_FACTORY("Max"));
-- {1 : "foo", 2 : "qwe" }

SetIsDisjoint

Check that the dictionary doesn't intersect by keys with a list or another dictionary.

So there are two options to make a call:

  • With the Dict<K,V1> and List<K> arguments.
  • With the Dict<K,V1> and Dict<K,V2> arguments.

Examples

SELECT SetIsDisjoint(ToSet(AsList(1, 2, 3)), AsList(7, 4)); -- true
SELECT SetIsDisjoint(ToSet(AsList(1, 2, 3)), ToSet(AsList(3, 4))); -- false

SetIntersection

Construct intersection between two dictionaries based on keys.

Arguments:

  • Two dictionaries: Dict<K,V1> and Dict<K,V2>.
  • An optional function that combines the values from the source dictionaries to construct the values of the output dictionary. If such a function has the (K,V1,V2) -> U type, the result type is Dict<K,U>. If the function is not specified, the result type is Dict<K,Void>, and the values from the source dictionaries are ignored.

Examples

SELECT SetIntersection(ToSet(AsList(1, 2, 3)), ToSet(AsList(3, 4))); -- { 3 }
SELECT SetIntersection(
    AsDict(AsTuple(1, "foo"), AsTuple(3, "bar")),
    AsDict(AsTuple(1, "baz"), AsTuple(2, "qwe")),
    ($k, $a, $b) -> { RETURN AsTuple($a, $b) });
-- { 1 : ("foo", "baz") }

SetIncludes

Checking that the keys of the specified dictionary include all the elements of the list or the keys of the second dictionary.

So there are two options to make a call:

  • With the Dict<K,V1> and List<K> arguments.
  • With the Dict<K,V1> and Dict<K,V2> arguments.

Examples

SELECT SetIncludes(ToSet(AsList(1, 2, 3)), AsList(3, 4)); -- false
SELECT SetIncludes(ToSet(AsList(1, 2, 3)), ToSet(AsList(2, 3))); -- true

SetUnion

Constructs a union of two dictionaries based on keys.

Arguments:

  • Two dictionaries: Dict<K,V1> and Dict<K,V2>.
  • An optional function that combines the values from the source dictionaries to construct the values of the output dictionary. If such a function has the (K,V1?,V2?) -> U type, the result type is Dict<K,U>. If the function is not specified, the result type is Dict<K,Void>, and the values from the source dictionaries are ignored.

Examples

SELECT SetUnion(ToSet(AsList(1, 2, 3)), ToSet(AsList(3, 4))); -- { 1, 2, 3, 4 }
SELECT SetUnion(
    AsDict(AsTuple(1, "foo"), AsTuple(3, "bar")),
    AsDict(AsTuple(1, "baz"), AsTuple(2, "qwe")),
    ($k, $a, $b) -> { RETURN AsTuple($a, $b) });
-- { 1 : ("foo", "baz"), 2 : (null, "qwe"), 3 : ("bar", null) }

SetDifference

Construct a dictionary containing all the keys with their values in the first dictionary with no matching key in the second dictionary.

Examples

SELECT SetDifference(ToSet(AsList(1, 2, 3)), ToSet(AsList(3, 4))); -- { 1, 2 }
SELECT SetDifference(
    AsDict(AsTuple(1, "foo"), AsTuple(2, "bar")), 
    ToSet(AsList(2, 3)));
-- { 1 : "foo" }

SetSymmetricDifference

Construct a symmetric difference between two dictionaries based on keys.

Arguments:

  • Two dictionaries: Dict<K,V1> and Dict<K,V2>.
  • An optional function that combines the values from the source dictionaries to construct the values of the output dictionary. If such a function has the (K,V1?,V2?) -> U type, the result type is Dict<K,U>. If the function is not specified, the result type is Dict<K,Void>, and the values from the source dictionaries are ignored.

Examples

SELECT SetSymmetricDifference(ToSet(AsList(1, 2, 3)), ToSet(AsList(3, 4))); -- { 1, 2, 4 }
SELECT SetSymmetricDifference(
    AsDict(AsTuple(1, "foo"), AsTuple(3, "bar")),
    AsDict(AsTuple(1, "baz"), AsTuple(2, "qwe")),
    ($k, $a, $b) -> { RETURN AsTuple($a, $b) });
-- { 2 : (null, "qwe"), 3 : ("bar", null) }
In this article:
  • DictCreate
  • DictItems
  • DictKeys
  • DictPayloads
  • DictLookup
  • DictContains
  • DictAggregate
  • SetIsDisjoint
  • SetIntersection
  • SetIncludes
  • SetUnion
  • SetDifference
  • SetSymmetricDifference
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC