Monetdbe Python UDF - monetdb

Given that monetdbe is a Python package, I'm optimistic that Python user-defined-functions are possible, but I haven't been able to find an example. I've tried this:
drop function every_other_letter;
create function every_other_letter(s string)
returns string
language python {
letters = "".join(s[::2])
return letters
};
select every_other_letter('foobarbaz');
I get this error:
ParseException:SQLparser:42000!Internal error while compiling statement: TypeException:user.p2_1[4]:'pyapi3.eval' library error in: Embedded Python 3 has not been enabled. Start server with --set embedded_py=3
Is there any way to set these flags in the embedded version?

The LANGUAGE PYTHON UDF's are a nice development feature in MonetDB's server installation but this feature requires an additional Python module to be loaded. And there is currently no way to configure monetdbe to load the required python module.
However assuming you have performance requirement for some production setting that are not met with the out-of-the-box SQL toolset in monetdbe, it makes more sense to implement a custom UDF extension written in C/C++. In regular MonetDB's server installation, the database server mserver5 can load an arbitrary extension module using the --loadmodule=<module> command option. But there is no equivalent monetdbe_option as of yet.
You might consider adding a feature request for this on monetdbe-python's github repository.
However there seems to exist a functioning undocumented workaround for adding UDF extensions to monetdbe. During its initialization, monetdbe attempts to load a set of hard coded modules. One of those is a module named "udf". You can create your own implementation of this module and load it into monetdbe.
Creating a native UDF extension is outside of the scope of this question and answer but there exist a nice up-to-date tutorial for writing UDF extensions for MonetDB here. Following the steps described in that tutorial, you end up with a SQL function revstr which has a user defined native implementation. The following Python script demonstrate its use:
from monetdbe import connect
with connect(autocommit=True) as con:
cur = cur.execute("select revstr('abcde')")
result = cur.fetchall()
print(result)
Make sure that the library containing your UDF extension is in the search path of the dynamic linker:
LD_LIBRARY_PATH=<path to directory containing lib_udf> python test.py

Related

How do I use ansibel-playbook to connect to mysql to execute SQL statements

I want to connect to mysql through ansible-playbook and execute SQL statements, but there is no relevant module in the official website of ansible. Does anyone know how to operate
When there does not exist an official module to do something, you basically have two choices:
Find a custom module that someone has written that will do it (such as this one).
Write a custom module that will do it.
Do it using the command module or any of the other arbitrary command modules.
In your case, for a one-off playbook, I would typically go with the third option as I don't much care for running custom modules. I would make sure (Via Ansible of course) that mysql was installed on the box you were running against, and build a mysql command line string based on what you need to do which you then run on a host with access to the DB server (or the DB server itself). That's the quickest and dirtiest method.

use of multiple custom scripts in metadata parameter of the LaunchInstanceDetails method in oci.core.model

I understand that the LaunchInstanceDetails method in oci.core.model has a parameter -> metadata , wherein one of the metadata key-names that can be used to provide information to Cloud-Init is -> “user_data” , which can be used to run custom scripts by Could-Init when provided in a base64-encoded format.
In my Python code to create a Windows VM,while launching the instance, I have a requirement to run 2 custom scripts:
Script to login to Windows machine via RDP – this is absolute(needs to be executed every time a new Windows VM is created without fail) – Currently , we have included this in the metadata parameter while launching the instance, as below:
instance_metadata['user_data'] = oci.util.file_content_as_launch_instance_user_data(path_init)
Bootstrap script to Install Chef during the initialization tasks - this is conditional ( this needs to run only if the user wishes to Install Chef and we internally handle it by means of a flag in the code) – Yet to be implemented as we need to identify if more than one custom script (conditional in this case) can be included.
Can someone help me understand if and how we can achieve to include multiple scripts(keeping in mind the conditional clause) in a single metadata variable or can we have multiple metadata or some other parameter in this service that could be utilised to run the Chef Installation script
I'd suggest combining these into a single script and using the conditional in a if statement to install Chef as required.

Is there any document about using Python preprocess with h2o steam?

The h2o steam website said Python preprocess with pojo
As .War is an optional, but I can not find any examples about doing this step by step,
Where can I find out more details about this? Or I better do it in Java only?
The situation is I have one python preprocess program, mainly use pandas to do some data munging before calling h2o to train/score the model. I want to use the
h2o steam as the score engine. The website mentions I can wrap the python and h2o pojo/mojo file together as a .war file, so I can call it through REST API. But I
can not find example or details about how to proceed. Also do I need to and if yes how to include these
python library like pandas in the war file?

Running Jython in ORacle Data Integrator (ODI) - how do I access the ODI packages

If I load up jython in ODI, or run a procedure in ODI designer itself, I can
import com.sunopsis.dwg.tools
import com.sunopsis.dwg.tools.ODIImportObject
but the only method available from ODIImportObject is main()
I want to run ODIImportObject in the same way I would from the command line using startcmd.bet, but hopefully reducing the cost of JVM start up each time.
but I cannot work out what to pass to ODIImportObject (the params I know, -filename etc, its how do i format the jython parameter to main() that gets me.
You didnt mention which version of ODI you are using, In the latest sdk there are Service Finders for the different artifacts you want to retrieve. Eg. PackageServiceFinder etc...

Desktop SPARQL client for Jena (TDB)?

I'm working on an app that uses Jena for storage (with the TDB backend). I'm looking for something like the equivalent of Squirrel, that lets me see what's being stored, run queries etc. This seems like an obvious thing to need, but my (perhaps badly phrased) google queries aren't turning up anything promising.
Any suggestions, please? I'm on XP. Even a command line tool would be helpful.
Take a look at my Store Manager tool which is part of the dotNetRDF Toolkit which I develop as part of the wider dotNetRDF project I maintain.
It provides a fairly basic GUI through which you can connect to various Triple Stores including TDB provided that you expose your dataset via Joseki/Fuseki. You need to have .Net 3.5 installed to run the apps in the toolkit.
If you don't already expose your TDB dataset via HTTP try using Fuseki as it is ridiculously easy to use and can be run just on your local machine when necessary to make your TDB store available via HTTP for use with my tool e.g.
java -jar fuseki-0.1.0-server.jar --update --loc data /dataset
Please see the Fuseki wiki for more information on running Fuseki and the various options. In the above example Fuseki is run with SPARQL Update enabled (the --update flag), using the TDB dataset located in the directory data (the --loc data argument) and with a base URI of /dataset for the data.
Once running you can use my tool to connect to a Fuseki server by going to File > New Generic Store Manager, selecting the "Fuseki" tab from the dialog that appears, entering the URI http://localhost:3030/dataset/data and then clicking "Connect to Fuseki".
Twinkle is a handy SPARQL client : http://www.ldodds.com/projects/twinkle/
As it happens I'm working on something similar myself, but it still needs a lot of work (check back in a month :) http://hyperdata.org/wiki/Scute
first download jena fusaki from
https://jena.apache.org/download/index.cgi
un-zip the file and copy the "jena-fuseki-1.0.1" to c drive
open cmd
type for accesing the folder
"cd C:\jena-fuseki-1.0.1"
then type
"java -jar fuseki-server.jar --update --loc data /dataset"
at last open a browser and type
"localhost:3030/"
remember you must first declear the enviorment verible(located in system poperties then advance tab)
and edit variable name call "Path" in the "System verible" to
"C:\jena-fuseki-1.0.1"
I also develop a SPARQL client, Open Source in Java Swing: EulerGUI.
In fact it does a lot more, see the manual:
http://eulergui.svn.sourceforge.net/viewvc/eulergui/trunk/eulergui/html/documentation.html
For the SPARQL feature, better take the EulerGUI minimal build:
http://sourceforge.net/projects/eulergui/files/eulergui/1.11/

Resources