DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How To Get Started With the Hazelcast Viridian Serverless

How To Get Started With the Hazelcast Viridian Serverless

In this tutorial, you will learn how to connect a client to a cluster and use SQL to query data in the cluster.

Fawaz Ghali, PhD user avatar by
Fawaz Ghali, PhD
·
Feb. 25, 23 · Tutorial
Like (2)
Save
Tweet
Share
4.76K Views

Join the DZone community and get the full member experience.

Join For Free

The Hazelcast Serverless means that Hazelcast manages the cloud infrastructure for you. Each Viridian Serverless cluster is an independent deployment of the Hazelcast Platform in a Kubernetes container. This design guarantees resource isolation, prevents resource stealing and provides isolated network access. Viridian Serverless clusters come in two types:1) Development: Capped storage. You can store at most 1 GiB of data; and 2) Production: Uncapped storage. The cluster scales as you add or remove data. In this tutorial, you’ll learn how to connect a client to a cluster and use SQL to query data in the cluster.

Before You Begin

You need the following:

  • A Hazelcast Viridian account
  • Access to a command prompt such as Terminal for Mac or Powershell for Windows.

Step 1. Start a Viridian Serverless Development Cluster

Development clusters are for fast, iterative development while you prototype your application. To create a development cluster, do the following:

  1. Sign into the Hazelcast Viridian console
  2. Click Create New Cluster
  3. Click Create Development Cluster
  4. Update the cluster name if you want to. You cannot change the cluster name after the cluster is created.
  5. Click Create Cluster
  6. Wait while your cluster is created. When the cluster is up and running, a Quick Connection Guide is displayed with instructions for connecting a sample client to it.

Step 2. Connect a Sample Client

To connect to your Viridian Serverless cluster, you need a Hazelcast client. The cluster comes with sample clients that are preconfigured to connect to your cluster and add some sample data to a map. A map is an in-memory, key/value data structure that is often used as a cache.

Before you begin:

  • Install Java 8-17 and set the JAVA_HOME environment variable to the location of your JRE.
  • If you’ve followed the onscreen Quick Connection Guide, jump straight to step 6.
    1. In the Quick Connection Guide on your cluster, click on the Java icon and then click Download.
    2. Extract the ZIP file
    3. From a command prompt, change to the root directory of the extracted files
    4. Execute one of the following commands to run your client:
      • If you use Linux or Mac, execute: ./mvnw clean compile exec:java@client-with-ssl
      • If you use Windows, execute: mvnw.cmd clean compile exec:java@client-with-ssl
    5. To query data in the cities map, you need to create a mapping to it. In step 3 of the Quick Connection Guide on your cluster, click Dashboard.
    6. In Cluster Details, click Management Center, and then from the top toolbar, click SQL Browser.
    7. Paste the following command into the SQL browser and execute it.
 
__key VARCHAR,

country VARCHAR,

city VARCHAR,

population INT)

type IMap OPTIONS('keyFormat'='varchar', 'valueFormat'='json-flat');


Step 3. Query the Cache with SQL

Now that you have some data in your cluster, you can query it using SQL. If you’re using the CLI, enter the following queries in the SQL prompt. If you’re using a client library, enter the following queries in the SQL browser.

  • Execute the following SELECT statement to query all data in the map.

SELECT * FROM cities;

The results are in random order because the data is distributed across the cluster.

  • Order the results by the key.

SELECT * FROM cities ORDER BY __key; 

Now you see the results start from key 1 and end with key 8. 

  • Query only the countries by filtering on the countries column.

SELECT country FROM cities;

  • Query only the cities by filtering on the cities column.

SELECT city FROM cities;

  • Change the output to display cities first in alphabetical order.

SELECT city, country FROM cities ORDER BY city;

  • Use a filter to display only countries where the name of the city is at least 11 characters long.

SELECT country FROM cities WHERE LENGTH(city) >= 11;

  • Use another filter to display only cities beginning with the letter 'L' where the length is greater than 6.

SELECT city FROM cities WHERE city LIKE 'L%' AND LENGTH(city) > 6;

Summary

In this tutorial, we learned how to connect to the Hazelcast Viridian Serverless and use SQL to query data. It is possible to connect to the Viridian using Java, Node.js, Python, .NET, C++, and Go. Once connected, you can manage your cluster through the Management Center. Hazelcast allows you to quickly build resource-efficient, real-time applications. You can deploy it at any scale, from small-edge devices to a large cluster of cloud instances. A cluster of Hazelcast nodes share both the data storage and computational load, which can dynamically scale up and down. When you add new nodes to the cluster, the data is automatically rebalanced across the cluster, and currently running computational tasks (known as jobs) snapshot their state and scale with processing guarantees.

Hazelcast Kubernetes cluster sql Java (programming language)

Published at DZone with permission of Fawaz Ghali, PhD. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Journey to Event Driven, Part 1: Why Event-First Programming Changes Everything
  • 19 Most Common OpenSSL Commands for 2023
  • Implementing PEG in Java
  • How To Best Use Java Records as DTOs in Spring Boot 3

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: