Skip to main content

Querying Staged ORC Files in Stage

Syntax

SELECT [<alias>.]<column> [, <column> ...] | [<alias>.]$<col_position> [, $<col_position> ...] 
FROM {@<stage_name>[/<path>] [<table_alias>] | '<uri>' [<table_alias>]}
[(
[<connection_parameters>],
[ PATTERN => '<regex_pattern>'],
[ FILE_FORMAT => 'ORC | <custom_format_name>'],
[ FILES => ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
)]

Tutorial

In this tutorial, we will walk you through the process of downloading the Iris dataset in ORC format, uploading it to an Amazon S3 bucket, creating an external stage, and querying the data directly from the ORC file.

1

Download Iris Dataset

Download the iris dataset from https://github.com/tensorflow/io/raw/master/tests/test_orc/iris.orc then upload it to your Amazon S3 bucket.

The iris dataset contains 3 classes of 50 instances each, where each class refers to a type of iris plant. It has 4 attributes: (1) sepal length, (2) sepal width, (3) petal length, (4) petal width, and the last column contains the class label.

2

Create External Stage

Create an external stage with your Amazon S3 bucket where your iris dataset file is stored.

CREATE STAGE orc_query_stage 
URL = 's3://databend-doc'
CONNECTION = (
AWS_KEY_ID = '<your-key-id>',
AWS_SECRET_KEY = '<your-secret-key>'
);
3

Query ORC File

SELECT *
FROM @orc_query_stage
(
FILE_FORMAT => 'orc',
PATTERN => '.*[.]orc'
);

┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ sepal_length │ sepal_width │ petal_length │ petal_width │ species │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┼──────────────────┤
5.13.51.40.2 │ setosa │
4.931.40.2 │ setosa │
4.73.21.30.2 │ setosa │
4.63.11.50.2 │ setosa │
53.61.40.2 │ setosa │
5.43.91.70.4 │ setosa │
4.63.41.40.3 │ setosa │
53.41.50.2 │ setosa │
4.42.91.40.2 │ setosa │
4.93.11.50.1 │ setosa │
5.43.71.50.2 │ setosa │
4.83.41.60.2 │ setosa │
4.831.40.1 │ setosa │
4.331.10.1 │ setosa │
5.841.20.2 │ setosa │
5.74.41.50.4 │ setosa │
5.43.91.30.4 │ setosa │
5.13.51.40.3 │ setosa │
5.73.81.70.3 │ setosa │
5.13.81.50.3 │ setosa │
│ · │ · │ · │ · │ · │
│ · │ · │ · │ · │ · │
│ · │ · │ · │ · │ · │
7.42.86.11.9 │ virginica │
7.93.86.42 │ virginica │
6.42.85.62.2 │ virginica │
6.32.85.11.5 │ virginica │
6.12.65.61.4 │ virginica │
7.736.12.3 │ virginica │
6.33.45.62.4 │ virginica │
6.43.15.51.8 │ virginica │
634.81.8 │ virginica │
6.93.15.42.1 │ virginica │
6.73.15.62.4 │ virginica │
6.93.15.12.3 │ virginica │
5.82.75.11.9 │ virginica │
6.83.25.92.3 │ virginica │
6.73.35.72.5 │ virginica │
6.735.22.3 │ virginica │
6.32.551.9 │ virginica │
6.535.22 │ virginica │
6.23.45.42.3 │ virginica │
5.935.11.8 │ virginica │
150 rows │ │ │ │ │
(40 shown) │ │ │ │ │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘

You can also query the remote ORC file directly:

SELECT
*
FROM
'https://github.com/tensorflow/io/raw/master/tests/test_orc/iris.orc' (file_format = > 'orc');
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today