Materialize Cloud Quickstart
If you're interested in trying out Materialize Cloud, let us know.
To get you started, we’ll walk you through the following:
- Signing up for Materialize Cloud
- Creating a Materialize Cloud deployment
- Connecting to the deployment from a terminal
- Connecting to a data source
- Running sample queries
Sign up for Materialize Cloud
Sign up at https://cloud.materialize.com.
Create and connect to a Materialize Cloud deployment
Once you sign up for Materialize Cloud and log in, you use the Deployments page to create, upgrade, or destroy deployments, and to obtain the TLS certificates you need to install on your local machine so you can connect to deployments.
By default, you can create up to two deployments. If you’re interested in more, let us know.
On the Deployments page, click Create deployment. Materialize creates a deployment and assigns it a name and hostname.
Click the Connect button in the same row as the deployment.
Click Download certificates.
Unzip the certificate package.
To connect to the deployment with the psql command-line tool, copy the command from the connection dialog and run it from the directory that contains the certificates.
The sample code below will not work unless you substitute your real hostname.
psql "postgresql://materialize@hostname:6875materialize? sslcert=materialize.crt& sslkey=materialize.key&sslrootcert=ca.crt"
If you’ve just created the deployment, you may need to wait a minute or two before you’ll be able to connect.
Connect to a real-time stream and a create materialized view
For this example, we’ll walk you through connecting to a PubNub stream as a data source. Note that PubNub demo streams should only be used for testing, since they do not meet the consistency and durability requirements necessary for Materialize to guarantee correctness over time.
From your shell, create a source (connect to the PubNub market orders stream):
CREATE SOURCE market_orders_raw FROM PUBNUB SUBSCRIBE KEY 'sub-c-4377ab04-f100-11e3-bffd-02ee2ddab7fe' CHANNEL 'pubnub-market-orders';
This streams data as a single text column containing JSON.
Extract the JSON fields for each order’s stock symbol and the bid price:
CREATE VIEW market_orders AS SELECT val->>'symbol' AS symbol, (val->'bid_price')::float AS bid_price FROM (SELECT text::jsonb AS val FROM market_orders_raw);
Create a materialized view that determines the average bid price, then return the average:
CREATE MATERIALIZED VIEW avg_bid AS SELECT symbol, AVG(bid_price) FROM market_orders GROUP BY symbol; SELECT * FROM avg_bid;
symbol | avg ------------+-------------------- Apple | 199.3392717416626 Google | 299.40371152970334 Elerium | 155.04668809209852 Bespin Gas | 202.0260593073953 Linen Cloth | 254.34273792647863
Wait a few moments and issue
SELECT * FROM avg_bid;again to get an updated result based on the latest data streamed in.