dotConnect for Google BigQuery Documentation
On this page
    Using GetSchema Method
    On this page

    dotConnect for Google BigQuery provides two ways of getting Google BigQuery metadata: the GetSchema method and the information schema tables.

    The GetSchema method lets you read schema information without writing queries and parsing the output. All information you may want to obtain is brought to you by a single function in an easy-to-process format. You can get information on datasets, tables, columns, and primary keys. The method is introduced in System.Data.Common.DbConnection.

    How To Use

    The GetSchema method is available in three overloads, each of them serves its own purpose. All overloads return a System.Data.DataTable object that contains information about schema elements.

    public override DataTable GetSchema();
    

    If you call the GetSchema method without parameters, or with the single parameter "MetaDataCollections" (which is actually the same), the table object returned by the method contains two columns. The first column of every row is a keyword allowed to be passed to the method (as the collectionName argument). The second column is the number of restriction values for this keyword (passed through the restrictionValues argument).

    public override DataTable GetSchema(string collectionName);
    

    GetSchema with one argument returns general information about the collection queried. For example, GetSchema("Tables") returns the list of the tables and views in the dataset specified in the DataSet Id connection string parameter, or in all datasets of the project if DataSet Id is not specified.

    public override DataTable GetSchema(string collectionName, string[] restrictionValues);
    

    In this overload, the first parameter is the name of a collection, and the second parameter is an array of restrictions to be applied when retrieving information. These restrictions specify which subset of the collection is returned. The first restriction of every collection, except the ones that have no restrictions, is the dataset name, followed by the table name and the column or key name. Restriction values are compared with the names for exact equality; wildcards aren't supported. A null or empty restriction value indicates that no restriction is applied. If the second parameter is null/Nothing, it is ignored.

    Instead of specifying the metadata collection name as a string constant, you may use the members of System.Data.Common.DbMetaDataCollectionNames and Devart.Data.BigQuery.BigQueryMetaDataCollectionNames as the first GetSchema argument value. The members of these classes are string fields; each field stores the corresponding metadata collection name. It is recommended to use these fields instead of hardcoding collection names as string constants. This allows misspellings to be caught at compile time and enables IntelliSense to suggest all available metadata collection names.

    GetSchema Method Reference

    The following table provides detailed information on metadata collections that can be retrieved using the GetSchema method, and restrictions that can be applied for them.

    Collection Name

    Number of restrictions

    Return value

    Restriction descriptions

    Columns

    3

    Returns the list of columns, their types, and some extra information.

    The first restriction is the dataset name. The second restriction is the table name. The third restriction is the column name.

    DataSets

    1

    Returns the list of datasets.

    The only restriction is the dataset name.

    DataSourceInformation

    0

    Returns information about the data source.

     

    MetaDataCollections

    0

    Returns this list. Same as using the GetSchema() method without parameters.

     

    PrimaryKeyColumns

    3

    Returns the list of columns that participate in primary keys.

    The first restriction is the dataset name. The second restriction is the table name. The third restriction is the primary key name.

    PrimaryKeys

    3

    Returns the list of primary keys.

    The first restriction is the dataset name. The second restriction is the table name. The third restriction is the primary key name.

    ReservedWords

    0

    Lists all reserved words of GoogleSQL.

     

    Restrictions

    0

    Returns the list of possible restrictions and their default values for the metadata collections.

     

    Tables

    2

    Returns the list of tables and views.

    The first restriction is the dataset name. The second restriction is the table name.

    GetSchema Resultset Columns

    For each metadata collection, dotConnect for Google BigQuery returns a DataTable with its own set of columns.

    Columns

    Column Name

    Data type

    Description

    DataSet

    string

    The dataset of the table, containing the column.
    Table

    string

    The table, containing the column.
    Name

    string

    The name of the column. A field of a STRUCT column is returned as a separate column named struct_name.field_name.
    Position

    int

    The position of the column in the table.
    DataType

    string

    The provider data type of the column, for example, LONG, STRING, DECIMAL, DATETIMEOFFSET.
    ProviderType

    int

    The provider type of the column. Corresponds to one of the System.Data.DbType values.
    NativeProviderType

    int

    The native type of the column. Corresponds to one of the BigQueryType values.
    Length

    Int64

    The maximum length of a STRING or BYTES column.
    Precision

    int

    The numeric precision of a NUMERIC or BIGNUMERIC column.
    Scale

    int

    The scale of a NUMERIC or BIGNUMERIC column.
    HasDefaultValue

    bool

    Indicates whether the column has a default value.
    DefaultValue

    string

    The default value expression of the column.
    Nullable

    bool

    Indicates whether the column is nullable.
    IsUnique

    bool

    Not used in dotConnect for Google BigQuery. Always false.
    IsPrimaryKey

    bool

    Indicates whether the column is a part of the table primary key.
    KeyName

    string

    The name of the primary key that includes the column.
    Required

    bool

    Indicates whether the column is declared as NOT NULL (REQUIRED mode).
    Queryable

    bool

    Always true.
    Createable

    bool

    Indicates whether the column can be set in INSERT statements. False for ARRAY columns.
    Updateable

    bool

    Indicates whether the column can be set in UPDATE statements. False for ARRAY columns.
    Sortable

    bool

    Always true.
    Filterable

    bool

    Always true.
    IsEnum

    bool

    Not used in dotConnect for Google BigQuery. Always false.
    IsMultiEnum

    bool

    Not used in dotConnect for Google BigQuery. Always false.
    Flags

    int

    For internal use.
    Unsigned

    bool

    Not used in dotConnect for Google BigQuery. Always false.
    RequiredDMLKey

    bool

    For internal use.
    DMLKey

    bool

    For internal use.
    IsArray

    bool

    Indicates whether the column is an ARRAY (REPEATED mode). ARRAY columns are returned as JSON text.
    Description

    string

    The description of the column.
    Collation

    string

    The collation of the column.

    DataSets

    Column Name

    Data type

    Description

    Name

    string

    The name of the dataset.

    DataSourceInformation

    Column Name

    Data type

    Description

    DataSourceProductName

    string

    The name of the product accessed by the provider.
    DataSourceProductVersion

    string

    The version of the product accessed by the provider.
    DataSourceProductVersionNormalized

    string

    The version of the product accessed by the provider, normalized so that it can be compared with String.Compare().
    ParameterMarkerFormat

    string

    A format string that represents how to format a parameter.
    ParameterMarkerPattern

    string

    A regular expression that matches a parameter marker. It matches parameter names with the @ prefix.
    ParameterNameMaxLength

    int

    The maximum length of parameter names in characters.
    ParameterNamePattern

    string

    A regular expression that matches valid parameter names.
    StatementSeparatorPattern

    string

    A regular expression that matches the statement separator.
    StringLiteralPattern

    string

    A regular expression that matches a string literal, and its match value is the literal itself.
    NumberOfIdentifierParts

    int

    The number of parts in a qualified table name: 2 (dataset and table).
    QuotedIdentifierPattern

    string

    A regular expression that matches a quoted identifier, and its match value is the identifier itself.
    QuotedIdentifierCase

    int

    Indicates how quoted identifiers are treated.
    CompositeIdentifierSeparatorPattern

    string

    A regular expression that matches the separator of the parts of a qualified name.
    IdentifierPattern

    string

    A regular expression that matches an identifier.
    IdentifierCase

    int

    Indicates how non-quoted identifiers are treated.
    GroupByBehavior

    int

    Specifies the relationship between the columns in a GROUP BY clause and the non-aggregated columns in the select list.
    OrderByColumnsInSelect

    bool

    Indicates whether columns in an ORDER BY clause must be in the select list.
    SupportedJoinOperators

    int

    Specifies what types of SQL join statements are supported.

    MetaDataCollections

    Column Name

    Data type

    Description

    CollectionName

    string

    The name of the collection.
    NumberOfRestrictions

    int

    The number of restrictions for the collection.

    PrimaryKeyColumns

    Column Name

    Data type

    Description

    Name

    string

    The name of the primary key column.
    DataSet

    string

    The dataset of the table, containing the primary key.
    Table

    string

    The name of the table, containing the primary key.
    Constraint

    string

    The name of the primary key, containing the column.
    Position

    int

    The position of the column in the primary key.

    PrimaryKeys

    Column Name

    Data type

    Description

    Name

    string

    The name of the primary key. dotConnect for Google BigQuery names primary keys as PK_<dataset>_<table>.
    DataSet

    string

    The dataset of the table, containing the primary key.
    Table

    string

    The name of the table, containing the primary key.

    ReservedWords

    Column Name

    Data type

    Description

    ReservedWord

    string

    The reserved word.

    Restrictions

    Column Name

    Data type

    Description

    CollectionName

    string

    The name of the collection.
    RestrictionName

    string

    The name of the restriction.
    RestrictionDefault

    string

    The default value, used if the restriction is not specified.
    RestrictionNumber

    string

    The number of the restriction for the metadata collection.

    Tables

    Column Name

    Data type

    Description

    DataSet

    string

    The dataset, containing the table.
    Name

    string

    The name of the table or view.
    Createable

    bool

    Indicates whether the table allows inserts. False for views.
    Updateable

    bool

    Indicates whether the table allows updates. False for views.
    Deletable

    bool

    Indicates whether the table allows deletes. False for views.
    Queryable

    bool

    Always true.
    Custom

    bool

    Not used in dotConnect for Google BigQuery. Always false.
    Schema

    string

    The dataset, containing the table.
    Type

    string

    The type of the object: TABLE or VIEW.
    CreationTime

    DateTime

    The time when the table was created.
    ExpirationTime

    DateTime

    The time when the table expires, or NULL if the table does not expire.
    PartitionedBy

    string

    The partitioning column of a partitioned table.
    RequirePartitionFilter

    bool

    Indicates whether queries to the table must filter on the partitioning column.
    ClusteredBy

    string

    The clustering columns of a clustered table.

    Samples

    The following code fragment is an elegant way to detect existence of a table.

    string tableName = "my_table";
    if (myConnection.GetSchema("Tables", new string[] { "my_dataset", tableName }).Rows.Count > 0)
    {
      Console.WriteLine("Table " + tableName + " exists in the dataset.");
    }
    

    The next sample shows how to retrieve columns information from a table and render it to console.

    static void GetTableInfo(BigQueryConnection myConnection, string dataSetName, string tableName)
    {
      myConnection.Open();
      DataTable myDataTable = myConnection.GetSchema("Columns", new string[] { dataSetName, tableName });
      for (int i = 0; i < myDataTable.Columns.Count; i++)
      {
        Console.Write(myDataTable.Columns[i].Caption + "\t");
      }
      Console.WriteLine();
      foreach (DataRow myRow in myDataTable.Rows)
      {
        foreach (DataColumn myCol in myDataTable.Columns)
        {
          Console.Write(myRow[myCol] + "\t");
        }
        Console.WriteLine();
      }
      myConnection.Close();
    }
    

    Also you can get metadata of a query result set using the GetSchemaTable method of BigQueryDataReader.

    See Also

    Metadata | Metadata Overview | Information Schema |