Converting DateTime Strings to Timestamps
In this recipe we’ll learn how to import DateTime strings into Pinot.
Pinot Version | 1.0.0 |
---|---|
Code | startreedata/pinot-recipes/datetime-string-to-timestamp |
Prerequisites
To follow the code examples in this guide, you must install Docker locally and download recipes.
Navigate to recipe
- If you haven’t already, download recipes.
- In terminal, go to the recipe by running the following command:
Launch Pinot Cluster and Kafka
You can spin up a Pinot Cluster and Kafka Broker by running the following command:
This command will run a single instance of the Pinot Controller, Pinot Server, Pinot Broker, Kafka, and Zookeeper. You can find the docker-compose.yml file on GitHub.
DateTime Strings in Pinot
Pinot automatically creates Timestamps from DateTime strings that are in the following format:
yyyy-mm-dd hh:mm:ss[.fffffffff]
- Millis since epoch
If we have a DateTime value in another format we’ll need to convert that value using a transformation function.
We’re going to import the following message into Kafka:
Add Schema and Table
Now let’s create a Pinot Schema and Table.
config/schema.json
config/table.json
This table has multiple transform configs defined that:
- Map
timestamp1
from the data source into theDate1
column - Map
timestamp2
from the data source into theDate2
column - Map
timestamp3
from the data source into theDate3
column, with help from the function. - Map
timestamp4
from the data source into theDate1
column
You can create the schema and table by running the following command:
Ingesting Data into Kafka
We can ingest a message into Kafka by running the following command:
Querying
Once that’s completed, navigate to localhost:9000/#/query and click on the dates table or copy/paste the following query:
You will see the following output:
Date1 | Date2 | Date3 | Date4 |
---|---|---|---|
2019-10-09 22:25:25.0 | 2019-10-09 21:25:25.0 | 2019-10-09 22:25:25.0 | 2019-10-09 22:25:25.0 |
Query Results