Loading...

The VastFrame

Master the core object for in-database analytics with VAST Orbit.


Overview

The VastFrame is the core object of VAST Orbit. It enables Python-based data manipulation without moving data from the VAST DataBase to local memory.

Key benefits:

  • In-database processing – All operations execute in VAST’s Trino engine

  • Minimal memory usage – Only metadata is stored in Python

  • Parallel execution – Leverage VAST’s distributed query engine

  • Lazy evaluation – Operations are optimized before execution

VastFrames behave like SQL views, formulating operations as queries that execute directly in the database.


Creating VastFrames

Load the Titanic dataset:

from vastorbit.datasets import load_titanic

load_titanic()
123
pclass
Integer
100%
123
survived
Integer
100%
Abc
name
Varchar(164)
100%
Abc
sex
Varchar(20)
100%
123
age
Double
79%
123
sibsp
Integer
100%
123
parch
Integer
100%
Abc
ticket
Varchar(36)
100%
123
fare
Double
99%
Abc
cabin
Varchar(30)
22%
Abc
embarked
Varchar(20)
99%
Abc
boat
Varchar(100)
37%
123
body
Integer
9%
Abc
home.dest
Varchar(100)
56%
131McCormack, Mr. Thomas Josephmale[null]003672287.75[null]Q[null][null][null]
231McCoy, Miss. Agnesfemale[null]2036722623.25[null]Q16[null][null]
331McCoy, Miss. Aliciafemale[null]2036722623.25[null]Q16[null][null]
431McCoy, Mr. Bernardmale[null]2036722623.25[null]Q16[null][null]
531McDermott, Miss. Brigdet Deliafemale[null]003309327.7875[null]Q13[null][null]
630McEvoy, Mr. Michaelmale[null]003656815.5[null]Q[null][null][null]
731McGovern, Miss. Maryfemale[null]003309317.8792[null]Q13[null][null]
831McGowan, Miss. Anna "Annie"female15.0003309238.0292[null]Q[null][null][null]
930McGowan, Miss. Katherinefemale35.00092327.75[null]Q[null][null][null]
1030McMahon, Mr. Martinmale[null]003703727.75[null]Q[null][null][null]
1130McNamee, Mr. Nealmale24.01037656616.1[null]S[null][null][null]
1230McNamee, Mrs. Neal (Eileen O'Leary)female19.01037656616.1[null]S[null]53[null]
1330McNeill, Miss. Bridgetfemale[null]003703687.75[null]Q[null][null][null]
1430Meanwell, Miss. (Marion Ogden)female[null]00SOTON/O.Q. 3920878.05[null]S[null][null][null]
1530Meek, Mrs. Thomas (Annie Louise Rowley)female[null]003430958.05[null]S[null][null][null]
1630Meo, Mr. Alfonzomale55.500A.5. 112068.05[null]S[null]201[null]
1730Mernagh, Mr. Robertmale[null]003687037.75[null]Q[null][null][null]
1831Midtsjo, Mr. Karl Albertmale21.0003455017.775[null]S15[null][null]
1930Miles, Mr. Frankmale[null]003593068.05[null]S[null][null][null]
2030Mineff, Mr. Ivanmale24.0003492337.8958[null]S[null][null][null]

From an existing table:

import vastorbit as vo

vo.VastFrame("titanic")

From a SQL query:

vo.VastFrame("SELECT pclass, AVG(survived) AS survived FROM titanic GROUP BY 1")
123
pclass
Integer
100%
123
survived
Double
100%
130.2552891396332863
220.4296028880866426
310.6191950464396285

For more examples, see VastFrame.


In-Database vs In-Memory

The following examples demonstrate performance advantages of in-database processing.

Note

These examples show the process without actual computation due to dataset size. When executed, in-database processing is significantly faster.

Load data into VAST:

vo.read_csv(
    "expedia.csv",
    schema="default",
    parse_nrows=20000000,
)

Create VastFrame (in-database):

import time

start_time = time.time()
expedia = vo.VastFrame("expedia")
print(f"Elapsed time: {time.time() - start_time:.2f}s")

All 4GB of data remains in VAST—no in-memory loading required.

Compare with pandas (in-memory):

Warning

Avoid running this on machines with less than 2GB RAM.

import pandas as pd

start_time = time.time()
expedia_df = pd.read_csv("expedia.csv")
print(f"Elapsed time: {time.time() - start_time:.2f}s")

Loading into pandas takes orders of magnitude longer and consumes significant memory.

Compute correlation matrix (pandas):

columns_to_drop = ["date_time", "srch_ci", "srch_co"]
expedia_df = expedia_df.drop(columns_to_drop, axis=1)

start_time = time.time()
expedia_df.corr()
print(f"Elapsed time: {time.time() - start_time:.2f}s")

Compute correlation matrix (VastFrame):

# Remove non-numeric columns
expedia.drop(columns=["date_time", "srch_ci", "srch_co"])

start_time = time.time()
expedia.corr(show=False)
print(f"Elapsed time: {time.time() - start_time:.2f}s")

VAST Orbit caches computed aggregations for instant retrieval:

Note

Disable caching with: vo.set_option("cache", False)

start_time = time.time()
expedia.corr(show=False)
print(f"Elapsed time: {time.time() - start_time:.2f}s")  # Nearly instant

Memory Usage

pandas DataFrame:

expedia_df.info()

Memory usage equals original file size (~4GB).

VastFrame:

VastFrame uses only ~37KB! By storing data in VAST and only tracking metadata in Python, memory usage is minimized.

Tip

In-database processing eliminates the need for downsampling, preserving all data insights.


VastFrame Structure

VastFrames are composed of VastColumn objects.

View all columns:

expedia.get_columns()

Access a column:

Note

VAST Orbit caches aggregations to avoid recomputation.

expedia["is_booking"].describe()
value
name"is_booking"
dtypeinteger
unique2.0
count149814.0
0138566
111248

View column catalog:

Each VastColumn maintains a catalog of user modifications:

expedia["is_booking"]._catalog

Enable SQL code generation:

vo.set_option("sql_on", True)
expedia["cnt"].describe()
-- Computing aggregations
SELECT
    APPROX_DISTINCT("cnt")
FROM (
    SELECT * FROM "expedia"
) AS VASTORBIT_SUBTABLE
LIMIT 1;
value
name"cnt"
dtypeinteger
unique30.0
count149814.0
mean1.4938523769474148
std1.2299667612009215
min1.0
approx_25%1.0
approx_50%1.0
approx_75%2.0
max47.0

Enable query timing:

vo.set_option("sql_on", False)
expedia = vo.VastFrame("expedia")
vo.set_option("time_on", True)
expedia.corr()

Cached results are instant:

import time

start_time = time.time()
expedia.corr()
print(f"Elapsed time: {time.time() - start_time:.2f}s")

Disable options:

vo.set_option("sql_on", False)
vo.set_option("time_on", False)

Query Relations

View current relation:

print(expedia.current_relation())

After modifications:

expedia["orig_destination_distance"].fillna(method="avg")
expedia["is_package"].drop()
print(expedia.current_relation())

Notice the SQL reflects the changes: is_package removed and COALESCE added for imputation.


VastFrame Attributes

VastFrames have two attribute types:

  • Virtual ColumnsVastColumn objects

  • Main attributes – Stored in _vars dictionary

Warning

Never modify _vars manually.

expedia._vars

Data Types

VAST Orbit recognizes four main data types:

  • int – Treated as categorical when low cardinality, otherwise numeric

  • real – Numeric data types

  • date – Date/timestamp types

  • text – Categorical data types

View data types:

expedia.dtypes()
dtype
"date_time"timestamp(3)
"site_name"integer
"posa_continent"integer
"user_location_country"integer
"user_location_region"integer
"user_location_city"integer
"orig_destination_distance"real
"user_id"integer
"is_mobile"integer
"channel"integer
"srch_ci"date
"srch_co"date
"srch_adults_cnt"integer
"srch_children_cnt"integer
"srch_rm_cnt"integer
"srch_destination_id"integer
"srch_destination_type_id"integer
"is_booking"integer
"cnt"integer
"hotel_continent"integer
"hotel_country"integer
"hotel_market"integer
"hotel_cluster"integer

Convert data types:

expedia["hotel_market"].astype("varchar")
expedia["hotel_market"].ctype()

View column category:

expedia["hotel_market"].category()

Saving and Loading

Save current state:

expedia.save()
expedia.filter("is_booking = 1")
📅
date_time
Timestamp(3)
100%
123
site_name
Integer
100%
123
posa_continent
Integer
100%
123
user_location_country
Integer
100%
123
user_location_region
Integer
100%
123
user_location_city
Integer
100%
123
orig_destination_distance
Real
100%
123
user_id
Integer
100%
123
is_mobile
Integer
100%
123
channel
Integer
100%
📅
srch_ci
Date
100%
📅
srch_co
Date
100%
123
srch_adults_cnt
Integer
100%
123
srch_children_cnt
Integer
100%
123
srch_rm_cnt
Integer
100%
123
srch_destination_id
Integer
100%
123
srch_destination_type_id
Integer
100%
123
is_booking
Integer
100%
123
cnt
Integer
100%
123
hotel_continent
Integer
100%
123
hotel_country
Integer
100%
Abc
hotel_market
Varchar
100%
123
hotel_cluster
Integer
100%
12013-07-01 12:17:3824236312102081.9774163858842900002013-07-072013-07-0810119548611310610718
22013-07-01 15:00:5524235057032081.9774163858841310112013-07-072013-07-181018811111219839110
32013-07-01 22:35:3623661744643269.98071272002013-07-152013-07-162012467761125035428
42013-07-02 12:57:06281552547802081.9774163858842473052013-07-082013-07-122111171331166829582
52013-07-02 13:23:3434320535452284200.1696251192013-07-142013-07-152012700061125057442
62013-07-02 15:50:43131461728425494.78552883052013-10-162013-10-2221187461126105298
72013-07-02 21:55:588477871366439186.60011996092013-09-082013-09-102014404531125070183
82013-07-03 11:32:22236626036620477.25721626092013-08-202013-08-232012573411125073017
92013-07-03 15:29:26242340356992081.9774163858841363092013-08-292013-09-02202540161131828315
102013-07-03 19:34:4524235057032081.9774163858842461012013-07-112013-07-121011245251125065648
112013-07-04 11:46:5524235057032081.9774163858841192002013-07-052013-07-07101199696113998881
122013-07-04 13:23:4423113805919264.53451004052013-07-132013-07-17221239996116105182689
132013-07-04 20:04:3724236431692081.9774163858843511012013-10-042013-10-071015165461131309132
142013-07-05 09:38:2224235057032081.9774163858842961002013-08-302013-08-31101122516116204275
152013-07-05 10:20:4524235057032081.9774163858842961002013-09-032013-09-04101226166116204145233
162013-07-05 10:52:2724235057032081.9774163858841492092013-09-112013-09-1220120332111312626485
172013-07-05 14:02:31304195597517742081.9774163858842661092013-09-162013-09-182018279111250123055
182014-10-15 11:30:2924235057032081.9774163858842545052014-10-212014-10-2310143130112063100111
192014-10-15 12:32:46371695962441087.36741224092014-11-012014-11-02201235076116701998
202014-10-15 12:57:4823661741663424.54993941092014-11-022014-11-0321124603111250104291

Restore previous state:

expedia = expedia.load()
print(expedia.shape())

Exporting to Database

VastFrame modifications don’t affect the underlying database. To persist changes, save to a new table.

Check storage requirements:

expedia.expected_store_usage(unit="Gb")
expected_size (Gb)max_size (Gb)type
"date_time"7.450580596923828e-090.0011162012815475464timestamp(3)
"site_name"0.000230808742344379430.0011162012815475464integer
"posa_continent"0.00013952516019344330.0011162012815475464integer
"user_location_country"0.00024504307657480240.0011162012815475464integer
"user_location_region"0.00035902019590139390.0011162012815475464integer
"user_location_city"0.00065008271485567090.0011162012815475464integer
"orig_destination_distance"7.450580596923828e-090.0011162012815475464real
"user_id"0.00053711049258708950.0011162012815475464integer
"is_mobile"0.00013952516019344330.0011162012815475464integer
"channel"0.000139535404741764070.0011162012815475464integer
"srch_ci"7.450580596923828e-090.0011138394474983215date
"srch_co"7.450580596923828e-090.0011138394474983215date
"srch_adults_cnt"0.00013952516019344330.0011162012815475464integer
"srch_children_cnt"0.00013952516019344330.0011162012815475464integer
"srch_rm_cnt"0.00013952516019344330.0011162012815475464integer
"srch_destination_id"0.00061217602342367170.0011162012815475464integer
"srch_destination_type_id"0.00013952516019344330.0011162012815475464integer
"is_booking"0.00013952516019344330.0011162012815475464integer
"cnt"0.00013995170593261720.0011162012815475464integer
"hotel_continent"0.00013952516019344330.0011162012815475464integer
"hotel_country"0.000330834649503231050.0011162012815475464integer
"hotel_market"0.000406352803111076350.011162012815475464varchar
"hotel_cluster"0.00026435032486915590.0011162012815475464integer
separator0.0032090786844491960.003209078684449196
header3.4831464290618896e-073.4831464290618896e-07
rawsize0.0082409242168068890.03892314434051514

Save to database:

expedia.to_db(
    "expedia_clean",
    relation_type="table",
)

Tip

VastFrames behave like views—they’re lightweight representations of database queries. Use to_db() only when you need to materialize results.

See also