All Products
Search
Document Center

MaxCompute:NGRAMS

Last Updated:Jul 24, 2023

Returns an n-gram array of the elements of the specified array.

Syntax

	ngrams(array(T), n)

Parameters

  • array: an input array.

  • n: the number of items in each n-gram.

Return value

An n-gram array of the elements of the specified array is returned.

If the n<=0 condition is met, an error is returned.

Examples

  • SELECT ngrams(array('foo', 'bar', 'baz', 'foo'), 2); 

    The following result is returned:

    [['foo', 'bar'], ['bar', 'baz'], ['baz', 'foo']]	
  • SELECT ngrams(array('foo', 'bar', 'baz', 'foo'), 3); 

    The following result is returned:

    [['foo', 'bar', 'baz'], ['bar', 'baz', 'foo']]
  • SELECT ngrams(array('foo', 'bar', 'baz', 'foo'), 4); 

    The following result is returned:

    [['foo', 'bar', 'baz', 'foo']] 
  • SELECT ngrams(array('foo', 'bar', 'baz', 'foo'), 5);

    The following result is returned:

    [['foo', 'bar', 'baz', 'foo']]
  • SELECT ngrams(array(1, 2, 3, 4), 2);

    The following result is returned:

    [[1, 2], [2, 3], [3, 4]]	

Related functions

NGRAMS is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.