SlicingDice API Docs

SlicingDice API Docs

Welcome to the SlicingDice API documentation. You'll find comprehensive guides and documentation to help you start working with SlicingDice as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Documentation

JOIN support


SlicingDice supports JOIN operations out of the box.

Imagine that you have this kind of data below, some of it is attribute data (name and age) and some is time-based / event data (actions).

User ID
Name
Age
Actions

UUID-01

Jeff

25

Add to Cart - {% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}
Pay Now - {% convert_date 'YYYY-MM-DDT10:22:10Z' '-1d' %}

curl -X POST https://api.slicingdice.com/v1/insert \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "UUID-01": {
            "name": "Jeff",
            "age": 25,
            "clicks": [
                {
                    "value": "Add to Cart",
                    "date": "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}"
                }, {
                    "value": "Pay Now",
                    "date": "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}"
                }, {
                    "value": "Support",
                    "date": "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}"
                }
            ],
            "table": "users"
        },
        "auto-create": ["table", "column"]
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

insert_data = {
    "UUID-01": {
        "table": "users",
        "age": 25,
        "name": "Jeff",
        "clicks": [
            {
                "date": "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}",
                "value": "Add to Cart"
            }, 
            {
                "date": "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}",
                "value": "Pay Now"
            }, 
            {
                "date": "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}",
                "value": "Support"
            }
        ]
    },
    "auto-create": [
        "table", 
        "column"
    ]
}

print(slicingdice.insert(insert_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONObject insertData = new JSONObject()
        .put("UUID-01", new JSONObject()
            .put("table", "users")
            .put("age", 25)
            .put("name", "Jeff")
            .put("clicks", new JSONArray()
                .put(new JSONObject()
                    .put("date", "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}")
                    .put("value", "Add to Cart"))
                .put(new JSONObject()
                    .put("date", "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}")
                    .put("value", "Pay Now"))
                .put(new JSONObject()
                    .put("date", "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}")
                    .put("value", "Support"))))
        .put("auto-create", new JSONArray()
            .put("table")
            .put("column"));

        JSONObject result = slicingdice.insert(insertData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

insert_data = {
    "UUID-01" => {
        "table" => "users",
        "age" => 25,
        "name" => "Jeff",
        "clicks" => [
            {
                "date" => "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}",
                "value" => "Add to Cart"
            }, 
            {
                "date" => "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}",
                "value" => "Pay Now"
            }, 
            {
                "date" => "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}",
                "value" => "Support"
            }
        ]
    },
    "auto-create" => [
        "table", 
        "column"
    ]
}

puts slicingdice.insert(insert_data)

const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const insertData = {
    "UUID-01": {
        "table": "users",
        "age": 25,
        "name": "Jeff",
        "clicks": [
            {
                "date": "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}",
                "value": "Add to Cart"
            }, 
            {
                "date": "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}",
                "value": "Pay Now"
            }, 
            {
                "date": "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}",
                "value": "Support"
            }
        ]
    },
    "auto-create": [
        "table", 
        "column"
    ]
};

slicingdice.insert(insertData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$insertData = array(
    "UUID-01" => array(
        "table" => "users",
        "age" => 25,
        "name" => "Jeff",
        "clicks" => array(
            array(
                "date" => "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}",
                "value" => "Add to Cart"
            ), 
            array(
                "date" => "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}",
                "value" => "Pay Now"
            ), 
            array(
                "date" => "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}",
                "value" => "Support"
            )
        )
    ),
    "auto-create" => array(
        "table", 
        "column"
    )
);

print_r($slicingdice->insert($insertData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var insertData = new Dictionary<string, dynamic>{
                {"UUID-01", new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"age", 25},
                    {"name", "Jeff"},
                    {"clicks", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"date", "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}"},
                            {"value", "Add to Cart"}
                        }, 
                        new Dictionary<string, dynamic>{
                            {"date", "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}"},
                            {"value", "Pay Now"}
                        }, 
                        new Dictionary<string, dynamic>{
                            {"date", "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}"},
                            {"value", "Support"}
                        }
                    }}
                }},
                {"auto-create", new List<dynamic>{
                    "table", 
                    "column"
                }}
            };

            var result = slicingdice.Insert(insertData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    insertData := map[string]interface{}{
        "UUID-01": map[string]interface{}{
            "table": "users",
            "age": 25,
            "name": "Jeff",
            "clicks": []interface{}{
                map[string]interface{}{
                    "date": "{% convert_date 'YYYY-MM-DDT12:54:12Z' '-10d' %}",
                    "value": "Add to Cart",
                },
                map[string]interface{}{
                    "date": "{% convert_date 'YYYY-MM-DDT10:22:10Z' '-5d' %}",
                    "value": "Pay Now",
                },
                map[string]interface{}{
                    "date": "{% convert_date 'YYYY-MM-DDT17:05:25Z' '-2d' %}",
                    "value": "Support",
                },
            },
        },
        "auto-create": []interface{}{
            "table",
            "column",
        },
    }

    fmt.Println(slicingdice.Insert(insertData))
}

If you were using any other database to store this data, SQL or NoSQL, for performance, storage space and separation of concerns reasons, you would normally create two different tables on your database:

  • User - Table with the UserID, Name and Age columns;
  • UserEvents - Table with the UserID, Actions and Timestamp columns.

As you can see, basically the first table would store the user's attribute data and the second the user's events data.

When making a query that uses both types of data, consequently both tables, you end up having to make a JOIN on your query, like this example below:

SELECT COUNT(DISTINCT User.UserID) 
FROM   UserEvents 
       INNER JOIN User 
               ON UserEvents.UserID = User.UserID 
WHERE  User.FirstName = 'Jeff' 
       AND UserEvents.Actions = 'Add to Cart' 
       AND UserEvents.Timestamp BETWEEN 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-10d" %}' 
           AND 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-1d" %}'; 

As you know, JOINs can be heavy and slow on normal databases, but not on SlicingDice.

SlicingDice was built to store attribute and event data in the same table, without forcing you to create different tables to split your attribute and event data.

Because of that, JOINs are performed out of the box on SlicingDice, without you even noticing it. Every time you make a query that uses an attribute and an event column on the same request, like the query below, a JOIN is transparently happening, but very fast.

[
    {
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            },
            "and",
            {
                "clicks": {
                    "equals": "Add to Cart",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-10d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]

JOIN support