新しい投稿

検索

記事
· 2022年7月5日 4m read

IRIS Data to Google Big Query - InterSystems Cloud SQL via Dataflow

        

How to include IRIS Data into your Google Big Query Data Warehouse and in your Data Studio data explorations.  In this article we will be using Google Cloud Dataflow to connect to our InterSystems Cloud SQL Service  and build a job to persist the results of an IRIS query in Big Query on an interval. 

If you were lucky enough to get access to Cloud SQL at Global Summit 2022 as mentioned in "InterSystems IRIS: What's New, What's Next", it makes the example a snap, but you can pull this off with any publicly or vpc accessible listener you have provisioned instead.

 

Prerequisites

 
Provision InterSystems Cloud SQL for temporary use
 
Setup Google Cloud Platform

Google Dataflow Job
If you followed the steps above you should have the following in your inventory to execute the job to read your InterSystems IRIS data and ingest it into Google Big Query using Google Dataflow.

In the Google Cloud Console, head over to Dataflow and select "Create Job from Template"

 
This is a rather unnecessary/exhaustive illustration on how to instruct you to fill out a form with the generated pre-requisites, but it calls out the source of the components...

 

 ... to round it out, make sure you expand the bottom section and supply your credentials for IRIS.

 

For the ones who found those screenshots offensive to your intelligence, here is the alternate route to go to keep you inside your comfort zone in the CLI to run the job:

gcloud dataflow jobs run iris-2-bq-dataflow \
--gcs-location gs://dataflow-templates-us-central1/latest/Jdbc_to_BigQuery \
--region us-central1 --num-workers 2 \
--staging-location gs://iris-2-datastudio/tmp \
--parameters connectionURL=jdbc:IRIS://k8s-c5ce7068-a4244044-265532e16d-2be47d3d6962f6cc.elb.us-east-1.amazonaws.com:1972/USER,driverClassName=com.intersystems.jdbc.IRISDriver,query=SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, SELF_REFERENCING_COLUMN_NAME, REFERENCE_GENERATION, USER_DEFINED_TYPE_CATALOG, USER_DEFINED_TYPE_SCHEMA, USER_DEFINED_TYPE_NAME, IS_INSERTABLE_INTO, IS_TYPED, CLASSNAME, DESCRIPTION, OWNER, IS_SHARDED FROM INFORMATION_SCHEMA.TABLES;,outputTable=iris-2-datastudio:irisdata.dataflowtable,driverJars=gs://iris-2-datastudio/intersystems-jdbc-3.3.0.jar,bigQueryLoadingTemporaryDirectory=gs://iris-2-datastudio/input,username=SQLAdmin,password=Testing12!

Once you have kicked off your job, you can bask in the glory a successful job run:

 
Results

Taking a look at our source data and query in InterSystems Cloud SQL...

 

... and then Inspecting the results in Big Query, it appears we do in fact, have InterSystems IRIS Data in Big Query.

 
Once we have the data in Big Query, it is trivial to include our IRIS data into Data Studio by selecting Big Query as the data source... this example below is missing some flair, but you can quickly see the IRIS data ready for manipulation in your Data Studio project.


 
 

3 Comments
ディスカッション (3)2
続けるにはログインするか新規登録を行ってください
お知らせ
· 2022年6月16日

George James Software at the Global Summit

Only a few days to go until the Global Summit! George James Software will be on hand to talk about any projects you may have on the horizon, such as application development, data and platform migration, system integration, training, and support – we can work with you to find practical and maintainable solutions that support the growing needs of your organization.

We're also running a User Group Session on Wednesday, July 22nd at 12pm. It's a great opportunity to find out more about our tools and ask us (and current users!) any questions.

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2022年6月3日 5m read

Questionnaire & Forms in FHIR : From creation to usage

This article will discuss FHIR Questionnaire and QuestionnaireResponse from the creation of the form to the upload on the server and how to fill them.

ディスカッション (0)2
続けるにはログインするか新規登録を行ってください
お知らせ
· 2022年5月31日

Apptools-admin - project admin tool for creating apps

I have been developing this project for many years. He helps me a lot in my daily work as a DBA and full stack developer.
This project has grown into a platform on which many of my other projects are based.
You can read more about the project in the article.
And I proposed this project for the contest, maybe it will be useful to you.

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2022年5月31日 4m read

Embedded Python で IRIS グローバル($LB) を Pandas Dataframe に変換する方法

InterSystems IRIS 2021.2 のバージョンより、Embedded Python を使用できるようになりました。

Embedded Python で Excel のデータを IRIS グローバルに格納する方法 では pandas.DataFrame のデータを InterSystems IRIS グローバルに保存する方法をご紹介しました。
こちらの記事では、その逆の「InterSystems IRIS グローバル($LB) を pandas.DataFrame に変換する」方法をご紹介します。

以下のようなグローバルを、Embedded Python を使用して DataFrame に変換します。

USER>zwrite ^ISJ
^ISJ=4
^ISJ(1)=$lb("Name","Age","Address")
^ISJ(2)=$lb("佐藤","50","東京")
^ISJ(3)=$lb("加藤","40","大阪")
^ISJ(4)=$lb("伊藤","30","京都")


%Library.GlobalクラスのGetクエリ を使用して取得し、iris.sql.execを使用して DataFrame に格納する方法があります。
ただし、こちらの方法はリスト形式($LB)のまま DataFrame に変換します。

USER>do $system.Python.Shell()     // :p でもOK
Python 3.9.19 (main, Oct  3 2024, 14:34:16) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>> mysql = "select name,value from %library.global_get('user','^ISJ()',,2,2)"
>>> resultset = iris.sql.exec(mysql)
>>> dataframe = resultset.dataframe()
>>> print (dataframe)
      name                        value
0  ^ISJ(1)          $lb("Name","Age","Address")
1  ^ISJ(2)          $lb("佐藤","50","東京")
2  ^ISJ(3)          $lb("加藤","40","大阪")
3  ^ISJ(4)          $lb("伊藤","30","京都")
>>>


こちらの結果の value を Name, Age, Address に分けて変換したい場合、既存の %Global.cls のクエリで行うことはできないため、

  1. IRIS側で、あらかじめリスト形式($LB)を分解してから処理する か、
  2. Python側で、IRISのリスト形式($LB)のまま格納されたデータを文字列置換などして DataFrame を作り直す

のどちらかを行う必要があります。

上記1の「IRIS側で処理する」場合、カスタムクラスクエリ を使用してグローバル内のリストの各データを返すクエリを作成し、それをSQL経由でアクセスする方法が考えられます。
カスタムクラスクエリを使用する方法は、SQL文ではなくユーザコードでクラスクエリを記述する方法はありますか? の記事でご紹介しています。

上の記事で紹介しているサンプルクラスを使用して、^ISJ のリストを要素別に抽出するサンプルを作成してみました。

^ISJの value の結果列が$LB形式で3要素なので、上の記事で使用しているサンプルを以下のように変更します。

★GFetchクラスメソッド

//Set Row=$LB($na(@glvn@(x)),@glvn@(x))
 Set Row=$LB($na(@glvn@(x)),$LIST(@glvn@(x),1),$LIST(@glvn@(x),2),$LIST(@glvn@(x),3))

★Gクエリ

// Query G(glvn As %String) As %Query(CONTAINID = 0, ROWSPEC = "Node:%String, Value:%String") [ SqlProc ]
Query G(glvn As %String) As %Query(CONTAINID = 0, ROWSPEC = "Node:%String, Value1:%String, Value2:%String, Value3:%String") [ SqlProc ]


実行例は以下のようになります。

USER>do $system.Python.Shell()     // :p のみでもOK
Python 3.9.5 (default, Apr 15 2022, 01:28:04) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>> mysql="select * from SQLUSER.TestStoredProc1_G('^ISJ')"
>>> resultset = iris.sql.exec(mysql)
>>> dataframe = resultset.dataframe()
>>> print (dataframe)
     node value1 value2  value3
0 ^ISJ(1)  Name   Age Address
1 ^ISJ(2)    佐藤    50      東京
2 ^ISJ(3)    加藤    40      大阪
3 ^ISJ(4)    伊藤    30      京都
>>>


今回使用したサンプルはこちらにあります
 👉https://github.com/Intersystems-jp/GlobalToPandasDataframe
 

~~~

(2022/06/01現在)
日本語対応はしていませんが、以下のような方法もあります。こちらは将来のバージョンで日本語対応予定です。

(2025/01/22現在)
2024.1より日本語対応しました。以下のような方法もあります。

%SYS.Pythonクラスの ToList()メソッドを使用して、IRISリストをPythonリストに変換する方法です。

1.以下のようなクラスを作成します。

Class User.PythonTest Extends %RegisteredObject
{

ClassMethod getDataFrame(gname As %String) [ Language = python ]
{
    import iris
    import pandas as pd
    g = iris.gref(gname)
    cnt=g[None]
    cnt=int(cnt)
    
    newlist=[]
    for i in range(1,cnt+1):
     datalist=iris.cls('%SYS.Python').ToList(g[i])
     newlist.append(datalist)
    newdf=pd.DataFrame(newlist[1:cnt],columns=[newlist[0][0],newlist[0][1],newlist[0][2]])
    print(newdf)
}

}


2.次のように実行します。
  使用するのは、上で使用した日本語データが含まれるリスト形式のグローバル(^ISJ)です。

USER>zw ^ISJ
^ISJ=4
^ISJ(1)=$lb("Name","Age","Address")
^ISJ(2)=$lb("佐藤","50","東京")
^ISJ(3)=$lb("加藤","40","大阪")
^ISJ(4)=$lb("伊藤","30","京都")

USER>:p
 
Python 3.9.19 (main, Oct  3 2024, 14:34:16) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>> iris.cls('User.PythonTest').getDataFrame('^ISJ')
  Name Age Address
0   佐藤  50      東京
1   加藤  40      大阪
2   伊藤  30      京都
>>>
1 Comment
ディスカッション (1)0
続けるにはログインするか新規登録を行ってください