Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SQLContext

Hierarchy

  • SQLContext

Index

Constructors

constructor

  • new SQLContext(options?: Partial<ContextProps>): SQLContext

Properties

Readonly context

context: Context

Accessors

id

  • get id(): number

Methods

createCSVTable

  • createCSVTable(tableName: string, filePaths: string[]): void
  • Create a SQL table from CSV file(s).

    example
    import {SQLContext} from '@rapidsai/sql';

    const sqlContext = new SQLContext();
    sqlContext.createCSVTable('test_table', ['test.csv']);

    Parameters

    • tableName: string

      Name of the table when referenced in a query

    • filePaths: string[]

      array of paths to CSV file(s)

    Returns void

createDataFrameTable

  • createDataFrameTable(tableName: string, input: DataFrame<any>): void
  • Create a SQL table from cudf.DataFrames.

    example
    import {Series, DataFrame, Int32} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new({type: new Int32(), data: [1, 2, 3]});
    const b = Series.new({type: new Int32(), data: [4, 5, 6]});
    const df = new DataFrame({'a': a, 'b': b});

    const sqlContext = new SQLContext();
    sqlContext.createDataFrameTable('test_table', df);

    Parameters

    • tableName: string

      Name of the table when referenced in a query

    • input: DataFrame<any>

      cudf.DataFrame

    Returns void

createORCTable

  • createORCTable(tableName: string, filePaths: string[]): void
  • Create a SQL table from Apache ORC file(s).

    example
    import {SQLContext} from '@rapidsai/sql';

    const sqlContext = new SQLContext();
    sqlContext.createORCTable('test_table', ['test.orc']);

    Parameters

    • tableName: string

      Name of the table when referenced in a query

    • filePaths: string[]

      array of paths to ORC file(s)

    Returns void

createParquetTable

  • createParquetTable(tableName: string, filePaths: string[]): void
  • Create a SQL table from Apache Parquet file(s).

    example
    import {SQLContext} from '@rapidsai/sql';

    const sqlContext = new SQLContext();
    sqlContext.createParquetTable('test_table', ['test.parquet']);

    Parameters

    • tableName: string

      Name of the table when referenced in a query

    • filePaths: string[]

      array of paths to parquet file(s)

    Returns void

describeTable

  • describeTable(tableName: string): Map<string, DataType>
  • Returns a map with column names as keys and the column data type as values.

    example
    import {Series, DataFrame, Int32} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new({type: new Int32(), data: [1, 2, 3]});
    const df = new DataFrame({'a': a});

    const sqlContext = new SQLContext();
    sqlContext.createTable('test_table', df);
    sqlContext.describeTable('test_table'); // {'a': Int32}

    Parameters

    • tableName: string

    Returns Map<string, DataType>

dropTable

  • dropTable(tableName: string): void
  • Drop a SQL table from SQLContext memory.

    example
    import {Series, DataFrame, Int32} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new({type: new Int32(), data: [1, 2, 3]});
    const b = Series.new({type: new Int32(), data: [4, 5, 6]});
    const df = new DataFrame({'a': a, 'b': b});

    const sqlContext = new SQLContext();
    sqlContext.createTable('test_table', df);
    sqlContext.sql('SELECT a FROM test_table');
    sqlContext.dropTable('test_table', df);

    Parameters

    • tableName: string

      Name of the table to drop

    Returns void

explain

  • explain(sql: string, detail?: boolean): string
  • Returns a break down of a given query's logical relational algebra plan.

    example
    import {Series, DataFrame} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new([1, 2, 3]);
    const df = new DataFrame({'a': a});

    const sqlContext = new SQLContext();
    sqlContext.createTable('test_table', df);

    sqlContext.explain('SELECT a FROM test_table'); // BindableTableScan(table=[[main,
    test_table]], aliases=<a href="cuml_src.UMAP.html#a">a</a>)

    Parameters

    • sql: string

      SQL query

    • detail: boolean = false

      if a physical plan should be returned instead

    Returns string

listTables

  • listTables(): string[]
  • Returns an array with the names of all created tables.

    example
    import {Series, DataFrame, Int32} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new({type: new Int32(), data: [1, 2, 3]});
    const df = new DataFrame({'a': a});

    const sqlContext = new SQLContext();
    sqlContext.createTable('test_table', df);
    sqlContext.listTables(); // ['test_table']

    Returns string[]

pull

  • pull(messageId: string): Promise<DataFrame<any>>
  • Returns a DataFrame pulled from the cache machine.

    example
    import {Series, DataFrame from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new([1, 2, 3]);
    const df = new DataFrame({'a': a});

    const sqlContext = new SQLContext();
    sqlContext.send(0, 0, "message_1", df);
    await sqlContext.pull("message_1"); // [1, 2, 3]

    Parameters

    • messageId: string

      The message id given when initially sending the DataFrame to the cache

    Returns Promise<DataFrame<any>>

send

  • send(id: number, ctxToken: number, messageId: string, df: DataFrame<any>): void
  • Sends a DataFrame to the cache machine.

    example
    import {Series, DataFrame from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new([1, 2, 3]);
    const df = new DataFrame({'a': a});

    const sqlContext = new SQLContext();
    sqlContext.send(0, 0, "message_1", df);

    Parameters

    • id: number

      The id of the destination SQLContext

    • ctxToken: number

      The token associated with the messageId

    • messageId: string

      The id used to pull the table on the destination SQLContext

    • df: DataFrame<any>

    Returns void

sql

  • sql(query: string, ctxToken?: number): ExecutionGraph
  • Query a SQL table and return the result as a DataFrame.

    example
    import {Series, DataFrame, Int32} from '@rapidsai/cudf';
    import {SQLContext} from '@rapidsai/sql';

    const a = Series.new({type: new Int32(), data: [1, 2, 3]});
    const b = Series.new({type: new Int32(), data: [4, 5, 6]});
    const df = new DataFrame({'a': a, 'b': b});

    const sqlContext = new SQLContext();
    sqlContext.createTable('test_table', df);

    await sqlContext.sql('SELECT a FROM test_table'); // [1, 2, 3]

    Parameters

    • query: string

      SQL query string

    • ctxToken: number = ...

      an optional content token used for communicating multiple nodes

    Returns ExecutionGraph