<commit_before>Chana
======

Avro Data Store based on Akka (persistence in progressing)

This project is named from Chinese word 刹那, which is a transliteration
of the word "Kasna" from Sanskrit, means "instant; split second". 

.. image:: https://travis-ci.org/wandoulabs/chana.png
   :target: https://travis-ci.org/wandoulabs/chana
   :alt: chana build status

Core Design
^^^^^^^^^^^

-  Each record is an actor (non-blocking)
-  Akka sharding cluster (easy to scale-out)
-  Locate field/value via
   `avpath <https://github.com/wandoulabs/avpath>`__
-  Scripting triggered by field updating events (JDK 8 JavaScript engine
   -
   `Nashorn <http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/>`__)
-  JPQL query on cluster (under heavy developing)

Run chana
^^^^^^^^^^

.. code:: shell

    $ sbt run

Or

.. code:: shell

    $ sbt clean compile dist
    $ ls target/universal/
    tmp  chana-0.2.0-SNAPSHOT.zip 

Then, copy chana-0.2.0-SNAPSHOT.zip to somewhere and unzip it

.. code:: shell

    $ cd chana-0.2.0-SNAPSHOT/bin
    $ ./chana

Access chana
^^^^^^^^^^^^^

Example 1: Simple Record
''''''''''''''''''''''''

Schema: PersonInfo.avsc

.. code:: json

    {
      "type" : "record",
      "name" : "PersonInfo",
      "namespace" : "chana",
      "fields" : [ {
        "name" : "name",
        "type" : "string"
      }, {
        "name" : "age",
        "type" : "int"
      }, {
        "name" : "gender",
        "type" : {
          "type" : "enum",
          "name" : "GenderType",
          "symbols" : [ "Female", "Male", "Unknown" ]
        },
        "default" : "Unknown"
      }, {
        "name" : "emails",
        "type" : {
          "type" : "array",
          "items" : "string"
        }
      } ]
    }

Try it:

.. code:: shell

    $ cd src/test/resources/avsc

    $ curl --data @PersonInfo.avsc 'http://127.0.0.1:8080/putschema/personinfo'
    OK

    $ curl 'http://127.0.0.1:8080/personinfo/get/1'
    {"name":"","age":0,"gender":"Unknown","emails":[]}

    $ curl --data-binary @PersonInfo.update 'http://127.0.0.1:8080/personinfo/update/1'
    OK

    $ curl 'http://127.0.0.1:8080/personinfo/get/1'
    {"name":"<NAME>","age":60,"gender":"Unknown","emails":[]}

    $ curl 'http://127.0.0.1:8080/personinfo/get/1/name'
    "<NAME>"

    $ ab -c100 -n100000 -k 'http://127.0.0.1:8080/personinfo/get/1?benchmark_only=1024'

Script example: (requires JDK8+)<commit_msg>Added simple jpql scripts example<commit_after>Chana
======

Avro Data Store based on Akka (persistence in progressing)

This project is named from Chinese word 刹那, which is a transliteration
of the word "Kasna" from Sanskrit, means "instant; split second". 

.. image:: https://travis-ci.org/wandoulabs/chana.png
   :target: https://travis-ci.org/wandoulabs/chana
   :alt: chana build status

Core Design
^^^^^^^^^^^

-  Each record is an actor (non-blocking)
-  Akka sharding cluster (easy to scale-out)
-  Locate field/value via
   `avpath <https://github.com/wandoulabs/avpath>`__
-  Scripting triggered by field updating events (JDK 8 JavaScript engine
   -
   `Nashorn <http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/>`__)
-  JPQL query on cluster (under heavy developing)

Run chana
^^^^^^^^^^

.. code:: shell

    $ sbt run

Or

.. code:: shell

    $ sbt clean compile dist
    $ ls target/universal/
    tmp  chana-0.2.0-SNAPSHOT.zip 

Then, copy chana-0.2.0-SNAPSHOT.zip to somewhere and unzip it

.. code:: shell

    $ cd chana-0.2.0-SNAPSHOT/bin
    $ ./chana

Access chana
^^^^^^^^^^^^^

Example 1: Simple Record
''''''''''''''''''''''''

Schema: PersonInfo.avsc

.. code:: json

    {
      "type" : "record",
      "name" : "PersonInfo",
      "namespace" : "chana",
      "fields" : [ {
        "name" : "name",
        "type" : "string"
      }, {
        "name" : "age",
        "type" : "int"
      }, {
        "name" : "gender",
        "type" : {
          "type" : "enum",
          "name" : "GenderType",
          "symbols" : [ "Female", "Male", "Unknown" ]
        },
        "default" : "Unknown"
      }, {
        "name" : "emails",
        "type" : {
          "type" : "array",
          "items" : "string"
        }
      } ]
    }

Try it:

.. code:: shell

    $ cd src/test/resources/avsc

    $ curl --data @PersonInfo.avsc 'http://127.0.0.1:8080/putschema/personinfo'
    OK

    $ curl 'http://127.0.0.1:8080/personinfo/get/1'
    {"name":"","age":0,"gender":"Unknown","emails":[]}

    $ curl --data-binary @PersonInfo.update 'http://127.0.0.1:8080/personinfo/update/1'
    OK

    $ curl 'http://127.0.0.1:8080/personinfo/get/1'
    {"name":"<NAME>","age":60,"gender":"Unknown","emails":[]}

    $ curl 'http://127.0.0.1:8080/personinfo/get/1/name'
    "<NAME>"

    #### JPQL Simple test
    $ echo 'SELECT COUNT(p.age), AVG(p.age), p.age FROM PersonInfo p WHERE p.age >= 30 ORDER BY p.age' | curl -d @- 'http://127.0.0.1:8080/putjpql/JPQL_NO_1'
   
    $ cat ./jpql.ask
    while :
    do
       sleep 1s
       curl 'http://127.0.0.1:8080/askjpql/JPQL_NO_1'
    done

    $ ./jpql.ask
    
    $ echo '{"age":40}' | curl -d @- 'http://127.0.0.1:8080/personinfo/put/1?benchmark_only=10240'

    $ ab -c100 -n100000 -k 'http://127.0.0.1:8080/personinfo/get/1?benchmark_only=1024'


Script example: (requires JDK8+)
{'fraction_non_alphanumeric': 0.1909689557855127, 'fraction_numerical': 0.043461900282220134, 'mean_word_length': 2.4296774193548387, 'pattern_counts': {'":': 17, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 15, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7334184', 'n_tokens_mistral': 2139, 'n_tokens_neox': 1968, 'n_words': 412}