You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

377 lines
11 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
" \"\"\"\n",
" This function will generate the SQL query for the resulting join\n",
" \"\"\"\n",
" \n",
" xo = args['xo']\n",
" x_ = args['xi']\n",
" xo_name = \".\".join([args['prefix'],xo['name'] ]) if 'prefix' in args else xo['name']\n",
" SQL = \"SELECT :fields FROM :xo.name \".replace(\":xo.name\",xo_name)\n",
" if not isinstance(x_,list):\n",
" x_ = [x_]\n",
" f = []#[\".\".join([args['xo']['name'],args['join']] )] \n",
" INNER_JOINS = []\n",
" for xi in x_ :\n",
" xi_name = \".\".join([args['prefix'],xi['name'] ]) if 'prefix' in args else xi['name']\n",
" JOIN_SQL = \"INNER JOIN :xi.name ON \".replace(':xi.name',xi_name)\n",
" value = \".\".join([xi['name'],args['join']])\n",
" f.append(value) \n",
" \n",
" ON_SQL = \"\"\n",
" tmp = []\n",
" for term in f :\n",
" ON_SQL = \":xi.name.:ofield = :xo.name.:ofield\".replace(\":xo.name\",xo['name'])\n",
" ON_SQL = ON_SQL.replace(\":xi.name.:ofield\",term).replace(\":ofield\",args['join'])\n",
" tmp.append(ON_SQL)\n",
" INNER_JOINS += [JOIN_SQL + \" AND \".join(tmp)]\n",
" return SQL + \" \".join(INNER_JOINS)\n",
" FROM (:sql)\n",
" GROUP BY :fields\n",
" ) \n",
" order by 1\n",
" \n",
" \"\"\".replace(\":sql\",base_sql)\n",
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cell_type": "code",
"execution_count": 6,
{
},