|
@@ -17,17 +17,9 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 1,
|
|
|
+ "execution_count": null,
|
|
|
"metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "name": "stdout",
|
|
|
- "output_type": "stream",
|
|
|
- "text": [
|
|
|
- "['data transport version ', '2.0.0']\n"
|
|
|
- ]
|
|
|
- }
|
|
|
- ],
|
|
|
+ "outputs": [],
|
|
|
"source": [
|
|
|
"#\n",
|
|
|
"# Writing to Google Bigquery database\n",
|
|
@@ -41,7 +33,7 @@
|
|
|
"MSSQL_AUTH_FILE= os.sep.join([AUTH_FOLDER,'mssql.json'])\n",
|
|
|
"\n",
|
|
|
"_data = pd.DataFrame({\"name\":['James Bond','Steve Rogers','Steve Nyemba'],'age':[55,150,44]})\n",
|
|
|
- "msw = transport.factory.instance(provider=providers.MSSQL,table='friends',context='write',auth_file=MSSQL_AUTH_FILE)\n",
|
|
|
+ "msw = transport.get.writer(provider=providers.MSSQL,table='friends',auth_file=MSSQL_AUTH_FILE)\n",
|
|
|
"msw.write(_data,if_exists='replace') #-- default is append\n",
|
|
|
"print (['data transport version ', transport.__version__])\n"
|
|
|
]
|
|
@@ -59,30 +51,15 @@
|
|
|
"\n",
|
|
|
"**NOTE**\n",
|
|
|
"\n",
|
|
|
- "It is possible to use **transport.factory.instance** or **transport.instance** they are the same. It allows the maintainers to know that we used a factory design pattern."
|
|
|
+ "By design **read** object are separated from **write** objects in order to avoid accidental writes to the database.\n",
|
|
|
+ "Read objects are created with **transport.get.reader** whereas write objects are created with **transport.get.writer**"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 5,
|
|
|
+ "execution_count": null,
|
|
|
"metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "name": "stdout",
|
|
|
- "output_type": "stream",
|
|
|
- "text": [
|
|
|
- " name age\n",
|
|
|
- "0 James Bond 55\n",
|
|
|
- "1 Steve Rogers 150\n",
|
|
|
- "2 Steve Nyemba 44\n",
|
|
|
- "\n",
|
|
|
- "--------- STATISTICS ------------\n",
|
|
|
- "\n",
|
|
|
- " _counts \n",
|
|
|
- "0 3 83\n"
|
|
|
- ]
|
|
|
- }
|
|
|
- ],
|
|
|
+ "outputs": [],
|
|
|
"source": [
|
|
|
"\n",
|
|
|
"import transport\n",
|
|
@@ -91,7 +68,7 @@
|
|
|
"AUTH_FOLDER = os.environ['DT_AUTH_FOLDER'] #-- location of the service key\n",
|
|
|
"MSSQL_AUTH_FILE= os.sep.join([AUTH_FOLDER,'mssql.json'])\n",
|
|
|
"\n",
|
|
|
- "msr = transport.instance(provider=providers.MSSQL,table='friends',auth_file=MSSQL_AUTH_FILE)\n",
|
|
|
+ "msr = transport.get.reader(provider=providers.MSSQL,table='friends',auth_file=MSSQL_AUTH_FILE)\n",
|
|
|
"_df = msr.read()\n",
|
|
|
"_query = 'SELECT COUNT(*) _counts, AVG(age) from friends'\n",
|
|
|
"_sdf = msr.read(sql=_query)\n",
|
|
@@ -104,25 +81,31 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "The cell bellow show the content of an auth_file, in this case if the dataset/table in question is not to be shared then you can use auth_file with information associated with the parameters.\n",
|
|
|
+ "An **auth-file** is a file that contains database parameters used to access the database. \n",
|
|
|
+ "For code in shared environments, we recommend \n",
|
|
|
"\n",
|
|
|
- "**NOTE**:\n",
|
|
|
+ "1. Having the **auth-file** stored on disk \n",
|
|
|
+ "2. and the location of the file is set to an environment variable.\n",
|
|
|
"\n",
|
|
|
- "The auth_file is intended to be **JSON** formatted"
|
|
|
+ "To generate a template of the **auth-file** open the **file generator wizard** found at visit https://healthcareio.the-phi.com/data-transport"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 3,
|
|
|
+ "execution_count": 1,
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"data": {
|
|
|
"text/plain": [
|
|
|
- "{'dataset': 'demo', 'table': 'friends'}"
|
|
|
+ "{'provider': 'sqlserver',\n",
|
|
|
+ " 'dataset': 'demo',\n",
|
|
|
+ " 'table': 'friends',\n",
|
|
|
+ " 'username': '<username>',\n",
|
|
|
+ " 'password': '<password>'}"
|
|
|
]
|
|
|
},
|
|
|
- "execution_count": 3,
|
|
|
+ "execution_count": 1,
|
|
|
"metadata": {},
|
|
|
"output_type": "execute_result"
|
|
|
}
|
|
@@ -130,10 +113,17 @@
|
|
|
"source": [
|
|
|
"\n",
|
|
|
"{\n",
|
|
|
- " \n",
|
|
|
+ " \"provider\":\"sqlserver\",\n",
|
|
|
" \"dataset\":\"demo\",\"table\":\"friends\",\"username\":\"<username>\",\"password\":\"<password>\"\n",
|
|
|
"}"
|
|
|
]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
}
|
|
|
],
|
|
|
"metadata": {
|