blob: 7055db98b2a4109aa4d52d3dd477978097f7075c [file] [log] [blame]
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"id": "6301516b-a3fa-48e2-a95f-0f79903a6cdd",
"metadata": {},
"outputs": [],
"source": [
"import unittest\n",
"from decimal import Decimal\n",
"import age \n",
"\n",
"resultHandler = age.newResultHandler()\n",
" \n",
"def evalExp(exp):\n",
" value = resultHandler.parse(exp) \n",
" print(type(value), \"|\", exp, \" --> \" ,value )\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "adf14fe9-692c-4701-86d4-8c84fd53d966",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'dict'> | {\"name\": \"Smith\", \"num\":123, \"yn\":true, \"bigInt\":123456789123456789123456789123456789::numeric} --> {'name': 'Smith', 'num': 123, 'yn': True, 'bigInt': Decimal('123456789123456789123456789123456789')}\n",
"<class 'list'> | [\"name\", \"Smith\", \"num\", 123, \"yn\", true, 123456789123456789123456789123456789.8888::numeric] --> ['name', 'Smith', 'num', 123, 'yn', True, Decimal('123456789123456789123456789123456789.8888')]\n",
"<class 'str'> | \"abcd\" --> abcd\n",
"<class 'int'> | 1234 --> 1234\n",
"<class 'float'> | 1234.56789 --> 1234.56789\n",
"<class 'decimal.Decimal'> | 12345678901234567890123456789123456789.789::numeric --> 12345678901234567890123456789123456789.789\n",
"<class 'decimal.Decimal'> | 12345678901234567890123456789123456789::numeric --> 12345678901234567890123456789123456789\n",
"<class 'bool'> | true --> True\n",
"<class 'float'> | -6.45161290322581e+46 --> -6.45161290322581e+46\n",
"<class 'decimal.Decimal'> | -123456789.99::numeric --> -123456789.99\n",
"<class 'decimal.Decimal'> | -6.45161290322581e+46::numeric --> -6.45161290322581E+46\n",
"<class 'int'> | 1234 --> 1234\n",
"<class 'float'> | NaN --> nan\n",
"<class 'float'> | -Infinity --> -inf\n",
"<class 'float'> | Infinity --> inf\n"
]
}
],
"source": [
"\n",
"mapStr = '{\"name\": \"Smith\", \"num\":123, \"yn\":true, \"bigInt\":123456789123456789123456789123456789::numeric}' \n",
"arrStr = '[\"name\", \"Smith\", \"num\", 123, \"yn\", true, 123456789123456789123456789123456789.8888::numeric]' \n",
"strStr = '\"abcd\"' \n",
"intStr = '1234' \n",
"floatStr = '1234.56789' \n",
"numericStr1 = '12345678901234567890123456789123456789.789::numeric' \n",
"numericStr2 = '12345678901234567890123456789123456789::numeric' \n",
"boolStr = 'true' \n",
"\n",
"evalExp(mapStr)\n",
"evalExp(arrStr)\n",
"evalExp(strStr)\n",
"evalExp(intStr)\n",
"evalExp(floatStr)\n",
"evalExp(numericStr1)\n",
"evalExp(numericStr2)\n",
"evalExp(boolStr)\n",
"\n",
"evalExp('-6.45161290322581e+46') \n",
"evalExp('-123456789.99::numeric') \n",
"evalExp('-6.45161290322581e+46::numeric') \n",
"evalExp('1234') \n",
"evalExp('NaN') \n",
"evalExp('-Infinity') \n",
"evalExp('Infinity') "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "8881804e-d71d-4704-b74c-376ed55be808",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'int'> 2251799813685425\n",
"<class 'str'> Person\n",
"<class 'str'> Smith\n",
"<class 'int'> 123\n",
"<class 'float'> 384.23424\n",
"<class 'decimal.Decimal'> 123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789\n",
"<class 'decimal.Decimal'> 123456789123456789123456789123456789.12345\n",
"<class 'bool'> True\n",
"<class 'NoneType'> None\n"
]
}
],
"source": [
"vertexExp = '''{\"id\": 2251799813685425, \"label\": \"Person\", \n",
" \"properties\": {\"name\": \"Smith\", \"numInt\":123, \"numFloat\": 384.23424, \n",
" \"bigInt\":123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789::numeric, \n",
" \"bigFloat\":123456789123456789123456789123456789.12345::numeric, \n",
" \"yn\":true, \"nullVal\": null}}::vertex'''\n",
"\n",
"vertex = age.parseAgeValue(vertexExp)\n",
"print(type(vertex.id), vertex.id)\n",
"print(type(vertex.label), vertex.label)\n",
"print(type(vertex[\"name\"]), vertex[\"name\"])\n",
"print(type(vertex[\"numInt\"]), vertex[\"numInt\"])\n",
"print(type(vertex[\"numFloat\"]), vertex[\"numFloat\"])\n",
"print(type(vertex[\"bigInt\"]), vertex[\"bigInt\"])\n",
"print(type(vertex[\"bigFloat\"]), vertex[\"bigFloat\"])\n",
"print(type(vertex[\"yn\"]), vertex[\"yn\"])\n",
"print(type(vertex[\"nullVal\"]), vertex[\"nullVal\"])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "0a70e467-9587-4eb7-b97d-895223009bcc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'int'> 2251799813685425\n",
"<class 'str'> Person\n",
"<class 'str'> Smith\n",
"<class 'int'> 2533274790396576\n",
"<class 'str'> workWith\n",
"<class 'int'> 3\n",
"<class 'decimal.Decimal'> 123456789123456789123456789.12345\n",
"<class 'int'> 2251799813685424\n",
"<class 'str'> Person\n",
"<class 'str'> Joe\n"
]
}
],
"source": [
"\n",
"pathExp = '''[{\"id\": 2251799813685425, \"label\": \"Person\", \"properties\": {\"name\": \"Smith\"}}::vertex, \n",
" {\"id\": 2533274790396576, \"label\": \"workWith\", \"end_id\": 2251799813685425, \"start_id\": 2251799813685424, \n",
" \"properties\": {\"weight\": 3, \"bigFloat\":123456789123456789123456789.12345::numeric}}::edge, \n",
" {\"id\": 2251799813685424, \"label\": \"Person\", \"properties\": {\"name\": \"Joe\"}}::vertex]::path'''\n",
"\n",
"path = age.parseAgeValue(pathExp)\n",
"vertexStart = path[0]\n",
"edge = path[1]\n",
"vertexEnd = path[2]\n",
"\n",
"print(type(vertexStart.id), vertexStart.id)\n",
"print(type(vertexStart.label), vertexStart.label)\n",
"print(type(vertexStart[\"name\"]), vertexStart[\"name\"])\n",
"\n",
"print(type(edge.id), edge.id)\n",
"print(type(edge.label), edge.label)\n",
"print(type(edge[\"weight\"]), edge[\"weight\"])\n",
"print(type(edge[\"bigFloat\"]), edge[\"bigFloat\"])\n",
"\n",
"print(type(vertexEnd.id), vertexEnd.id)\n",
"print(type(vertexEnd.label), vertexEnd.label)\n",
"print(type(vertexEnd[\"name\"]), vertexEnd[\"name\"])\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62b7273f-ac6c-4dec-af7e-0467daa140f4",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}