R How to use file.exist with an object connection - r

In R, I have an object of type connection and would prefer to use directly the connection instead of the initial path to check if the file exists:
file.exist("path")
Is there any method to get the path from the connection, apparently it is not in the attributes, but I can still see the path when printing the connection in the console...

The solution from #Stefan F comment is working perfectly :
path <- summary(my_connection)$description

Related

Cannot load the GraphML file I just saved

I'm using Gremlin Server.
I save the contents of the database in an XML file (GraphML) with this line:
g.io(path).write().iterate()
To load the file I use this line:
g.io(path).read().iterate();
And then I get this error:
connection.js:282
new ResponseError(util.format('Server error: %s (%d)', response.status.message, response.status.code), response.status));
^
ResponseError: Server error: For input string: "-2555865115" (500)
This error is coming from gremlin server.
If I search for this value in the XML file (-2555865115) and I remove the last character (-255586511) then the problem is solved.
Why this happens? How can I fix this issue? The database is always saving a file that I have to fix manually.
If I have to change something in the configuration files of Gremlin Server, can you please tell me which file to modify and how? because I never did that before.
I'm using Gremlin server in my local computer just for testing, without any changes.
EDIT:
I changed conf/tinkergraph-empty.properties to this:
gremlin.tinkergraph.vertexIdManager=ANY
gremlin.tinkergraph.edgeIdManager=ANY
gremlin.tinkergraph.vertexPropertyIdManager=ANY
I restarted, but I get the same error when loading the XML file.
Given that removing the last integer from your numerical value solved the problem, I'd speculate you're hitting a limit; specifically, the lowest value an integer can have.
In Java, that value is -2147483647, and that happens to be the language that the default implementation of Gremlin Server is written in. As such, it's likely that the deserialization process is failing while trying to interpret that value as an integer. Since the value is below the minimum value of an integer, and since the error message talks about it being an input string, Integer.parseInt("-2555865115") is probably the call that's failing behind the scenes.
If Gremlin is both serializing and de-serializing the data, it might be a bug in that implementation, and you might want to file an issue. In the mean time, consider implementing and registering a custom serializer to give yourself more control over how the IO process works.

How Do I Format A Connection String to Analysis Server in RMDX?

Sorry in advance for asking a very basic/newbie question, but I'm trying to use RMDX to query some data from a Microsoft Analysis Server from RStudio. RMDX is the only package I've been able to successfully install. I've also tried adding X4R w install_github but had some difficulty (and in any case X4R also seems to use a URL as the connection string), and I've tried adding olapR from my RClient library to my R 3.5.2 library, but I get an error about it being made for a version of R with different internals.
RMDX takes a URL as a connection string and I don't know how to format the data connection... correctly, I guess? I've only used sql with RODBC in R before, and setting up a data source via ODBC Data Source Administrator doesn't work for the data warehouse.
Obviously I'm missing a lot of basics/theory/fundamentals so I'm just kind of shooting in the dark, but I've tried "localhost//[server-name]," "https://[server-name]," and copying the connection string used for some of the microsoft bi dashboards that connect to the same data warehouse that I want to query, and none work. Does anyone know how to solve this issue, or can anyone suggest an alternative way of executing MDX queries from RStudio? Thanks!
After experimenting on a similar route like you - I have ended up writing a powershell script that connects to the MS SSAS or OLAP Cube via its "URL" (usually you will use the URL string that has the 'msmdpump.dll' mentioned in it somewhere - usually at the end of it - as the $con or connection string). After that (meaning in the ps script more precisely it is a module) I heavily rely on the AdomdClient object and its properties, something along these lines
#establish SSAS ADOMD Client and open connection
[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.AnalysisServices.AdomdClient\") | Out-Null;
\
echo 'Connecting to Database/Cube via Powershell module!'
$con = new-object Microsoft.AnalysisServices.AdomdClient.AdomdConnection($connectionString)
$con.Open()
$command = new-object Microsoft.AnalysisServices.AdomdClient.AdomdCommand($MDXquery, $con)
$dataAdapter = new-object Microsoft.AnalysisServices.AdomdClient.AdomdDataAdapter($command)
$ds = new-object System.Data.DataSet
#fetch data
echo 'fill data container w cube data'
$dataAdapter.Fill($ds)
$con.Close();
....
After that I call this ps script via system2(command = "powershell",...) from within R with the various connectionstring, MDX (query) and so on parameters, save the result in a temp folder as a csv file and then load that back into my R session again.
Hope that helps.

CORB job using ModuleExecutor set up

I have simple search query on CORB job. I am following https://github.com/marklogic-community/corb2/wiki/ModuleExecutor-Tool for the set up that looks for one xqy file (PROCESS-MODULE). I don't have any issue on regular CORB job but with this set up I am getting
com.marklogic.xcc.exceptions.XccConfigException: Unrecognized connection scheme: null
Can somebody please help me figure out why?
The regular corb job is working and is fully functional but when I use https://github.com/marklogic-community/corb2/wiki/ModuleExecutor-Tool approach I am getting this XCC exception and I can't figured out why.
It sounds as if the XCC connection string is malformed, or you haven't set the XCC connection URI at all. The XCC connection string should start with the "xcc://" scheme.
The XCC-CONNECTION-URI can be passed on the commandline as the first argument to the ModuleExecutor Main method:
java -cp marklogic-corb-2.4.1.jar:marklogic-xcc-9.0.8.jar -DOPTIONS-FILE=job.options \
com.marklogic.developer.corb.ModuleExecutor xcc://user:password#localhost:8123
Or the property can be set in the options file:
XCC-CONNECTION-URI=xcc://user:password#localhost:8123
Or it can be set as a system property:
-DXCC-CONNECTION-URI=xcc://user:password#localhost:8123

ImportError: No module named None

*** Test cases ***
TestDB
Connect To Database Using Custom Params None database='TestDB', user='system', password='system', host='10.91.41.101', port=1521
Please help - the error is:
ImportError: No module named None
The error most probably comes from the way you call Connect To Database Using Custom Params - the first argument you're passing, which should be the value for the dbapiModuleName, is passed as a string object, with the value "None".
If you wanted to call it with the value None object (as it's written in the library's help), that should have been ${None} in robotframework format.
I doubt that's going to work though - the DatabaseLibrary probably needs some DB type identifier. So if you are using postgres for example, you'd call it with "psycopg2":
Connect To Database Using Custom Params psycopg2 database='TestDB', user='username', password='mypass', host='10.1.1.2', port=1521
Have in mind you'd need the DB driver already installed through pip, psycopg2 in the case of the example here.
P.S. please don't paste actual credentials in SO.
I assume your question should have been posted something like this...
Issue
When attempting to execute the following test case in Robot Framework, I receive the following error: ImportError: No module named None
Here is the test case in question:
*** Test Cases ***
TestDB
Connect To Database Using Custom Params None database='TestDB', user='system', password='system', host='10.91.41.101', port=1521
If so, your issue may be as simple as spacing. Robot Framework can accept pipes as delimiters, but if you choose to use spaces, you must use 2 or more.
Based on your copy/paste, it looks like you have only one space between Connect To Database Using Custom Params and None (which, I'm assuming you're specifying as the DB API Python module the system default - not sure if that's recommended or supported). Make sure you have at least two spaces (I generally try for 4 unless I have a lot of parameters) between keywords and their parameters.
So:
Make sure you have at least two spaces between the keyword and parameters. Here is the keyword in question's reference.
Verify that you don't need to specify the Python database driver for the database you are using. Based on the port you've specified, I'm guessing it's an Oracle database. Here's a list of Python Oracle drivers.
I had a similar error and read on it for hours not knowing I hadn't created a .env file yet. credit to a friend who brought me to this page. (which gave me the hint on what I was missing).
I created a .env file in my root folder where the manage.py file is and configured my database settings and voila. Thanks Suraj

Use RDCOMClient to connect R to SSAS Cube

I'm trying to establish a connection between R and a Sequel Server Analysis Services (SSAS) Cube. Similar questions have been asked before here and here, but I haven't been able to find an easy answer. HTTP access through the X4R package is discussed here, but the SSAS cube I have access to is not configured for HTTP connections.
Using the RDCOMClient library, I can create an "ADO Connection" object with
con <- COMCreate("ADODB.Connection")
Following the script here, I would like to write something like
con[["ConnectionString"]] <- paste(
"Provider=MSOLAP.4",
"Server=myserver",
"Initial Catalog=mycatalog",
sep = ";")
con$Open()
to specify the connection string and open the connection. The labels myserver and mycatalog are set to their appropriate values based on the connection I am able to establish between Excel and SSAS.
However, my connection string is probably not correctly specified because I get the error
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
I don't know how to debug this error either. Could someone advise
the appropriate COM class to use (i.e. is "ADODB.Connection" correct?)
the key-value pairs required for the "ConnectionString" element of the COM class object
where I can find more information about these topics (the MSDN ADO MD for developers pages are quite difficult for a non-developer)
if there is a better way to go about establishing a connection between R and an SSAS Cube
How is the path to "myserver" defined? I got this error when I confused R and SSAS with backslashes/forward slashes.
I used this post to help with correct syntax and then the error disappeared (i.e. I used backwards slashes and added an extra backslash for each one to escape them)

Resources