Query Data in Azure Blob Storage
- how-to
To query data in Azure Blob Storage, you create an external link and associate it with an external collection.
Prerequisites
To use the Enterprise Analytics UI to query data, you need the Enterprise Analytics Access role along with specific privileges.
You need several pieces of information about the Azure Blob Storage container with the data you want to query.
Credentials
To create an external link for private data in an Azure Blob Storage container, you must supply credentials for the storage account. These credentials must have permission to list and read data from the container. For more information, see Manage storage account access keys in the Microsoft Azure documentation.
You do not need credentials for publicly available data in Azure Blob Storage.
| When you create an external link, be sure to follow best practices for security. Couchbase recommends that you grant the minimum possible permissions to perform the required operations, and allow access only to the required data and resources. You should never use root account credentials. |
The Location Path
When you create an external collection based on an Azure Blob Storage container, you can supply a path to the files Enterprise Analytics queries.
A path consists of one or more prefixes that define a hierarchical organization, using a format such as topLevel/nextLevel/lowestLevel.
The path does not include filenames.
| If you use the Azure portal, prefixes are also referred to as folders. |
To make querying the external data source as efficient as possible, you should supply a path that’s as specific and precise as possible. You can use static prefixes, dynamic prefixes, or a mixture of both to define a path. For information about static and dynamic prefixes, see Design a Location Path.
| Because you cannot index the data located in an external store, Couchbase encourages thoughtful design of the paths used in external collections. |
For information about using prefixes for data in Azure Blob Storage, see List blobs in the Microsoft Azure documentation.
You can select a subset of the files in a location by using fields that include and exclude filenames.
Create a Link for Azure Blob Storage
-
In the UI, select the Workbench tab.
-
Select + new link.
-
In the Link Name field, enter a name for the link.
-
In the Link Type field, select Azure Blob Storage.
-
In the Authentication field, add the credentials for your Azure storage account.
-
Click Save & Continue to proceed. Enterprise Analytics creates the link to the Azure Blob Storage data source.
Create a Collection for Azure Blob Storage Data
-
In the UI, select the Workbench tab.
-
On the created Azure Blob Storage link, select + collection.
-
In the Collection Name field, enter a name for the collection.
-
In the Database field, select the database.
-
In the Scope field, select the scope.
-
In the Container Name field, enter the name of the Azure Blob Storage container. Supply only the name of the container, not a URL.
-
In the Path field, enter one or more prefixes separated by slashes
/to identify the location of the files you want to query. Do not include filenames in the path. To query files located at the top-most, or container, level, leave the path blank. See Design a Location Path. -
In the File Format field, select the format of the files at that destination. Depending on the format you select, you may see additional fields:
-
CSV and TSV
-
Parquet
-
JSON
-
Avro
-
Define the data types for the fields in the files as a comma-separated list of
<field-name> <datatype>values. The<datatype>is one of the primitive data types. If the field’s value does not match the data type, Enterprise Analytics ignores the record. You can also specify theNOT UNKNOWNflag after the data type to have Enterprise Analytics ignore the record if the value ismissingornull. For example:id BIGINT NOT UNKNOWN, firstname STRING, lastname STRING
-
Clear File includes header row if the first line of your CSV file is not a list of the columns in the file.
-
If your data uses a value other than an empty string (
"") to indicate a null value, select Use custom string as Null and enter the value.
Choose whether Enterprise Analytics should parse embedded JSON data and convert decimal values to doubles.
Choose whether Enterprise Analytics should parse embedded JSON data and convert decimal values to doubles.
Choose whether Enterprise Analytics should parse embedded JSON data and convert decimal values to doubles.
-
-
Optionally, use either the Include or Exclude field to specify files to include in, or exclude from, queries. You can use the following wildcards:
-
*matches any character or characters -
?matches any single character -
[ sequence ]matches any characters in the supplied sequence -
[! sequence ]matches any characters not in the supplied sequenceFor example, if the container stores both JSON and Parquet files, you can enter
*.JSONin the Include field to query only the files that are in JSON format.
-
-
Click Save. Your collection appears under the scope in the explorer.
| Because the data in an external collection is not ingested into Enterprise Analytics and remains on the external host, Enterprise Analytics cannot index it. |