How to use MarkLogic xdmp:document-insert() function with 'options' argument - xquery

When I run this example (from the documentation), I get the error:
SEC-INVALIDPERM: xdmp:document-insert("/example.xml", <a>aaa</a>, <options xmlns="xdmp:document-insert"><permissions><sec:permission xmlns:sec="http://marklogic.com/xdm...</options>) -- Invalid permission
xquery version "1.0-ml";
xdmp:document-insert(
"/example.xml",
<a>aaa</a>,
<options xmlns="xdmp:document-insert">
<permissions>{xdmp:default-permissions()}</permissions>
<collections>{
<collection>/my/additional/collection</collection>,
for $coll in xdmp:default-collections()
return <collection>{$coll}</collection>
}</collections>
<quality>10</quality>
</options>)
The function works if there is no options argument.
Running just xdmp:default-permissions() returns
<sec:permission xmlns:sec="http://marklogic.com/xdmp/security">
<sec:capability>update</sec:capability>
<sec:role-id>15080714410678341621</sec:role-id>
</sec:permission>
<sec:permission xmlns:sec="http://marklogic.com/xdmp/security">
<sec:capability>read</sec:capability>
<sec:role-id>15080714410678341621</sec:role-id>
</sec:permission>
How can I use this function with the options argument without this happening?

You might be running this in MarkLogic 8 or below. This will work in MarkLogic 9 (which is the latest as of the time of writing).
The various options to xdmp:document-insert were separate parameters in MarkLogic 8 and below, which were aggregated into a single options node in MarkLogic 9.
You might want to check out the signature difference between the 2 variants:
xdmp:document-insert - MarkLogic 8
xdmp:document-insert - MarkLogic 9

Related

IFC to Cypher via python and IfcOpenShell

I want to convert an IFC file to a graph database to extract adjacency and accessibility of the spaces in the IFC model.
I wanted to use Neo4j, and as a part of this job, I need to extract a Cypher code from the IFC file.
I found this code but when I run it, I encounter the error below:
AttributeError Traceback (most recent call last)
<ipython-input-1-b13704b3ee10> in <module>
20 typeDict = IfcTypeDict()
21
---> 22 assert typeDict['IfcWall'] == ('GlobalId', 'OwnerHistory', 'Name', 'Description', 'ObjectType', 'ObjectPlacement', 'Representation', 'Tag')
23
24 nodes = []
<ipython-input-1-b13704b3ee10> in __missing__(self, key)
15 class IfcTypeDict(dict):
16 def __missing__(self, key):
---> 17 value = self[key] = ifcopenshell.create_entity(key).wrapped_data.get_attribute_names()
18 return value
19
AttributeError: 'str' object has no attribute 'get_attribute_names'
Can anyone help me with this? or any other idea about how I can perform this task?
any help would be greatly appreciated.
Regards.
It seems this script was created for IfcOpenShell v0.5 compiled for IFC2x3 while you are using IfcOpenShell v0.6, which is unfortunately not backwards-compatible. You could either try to use v0.5 or update the script to the v0.6 API.
If you use v0.5, be aware that this version was compiled for a specific IFC version. I believe the published packages are for IFC2x3, thus it will not work with IFC4 files. You could compile for IFC4 though, but then would loose IFC2x3 support. The assertion wouldn't work anymore, because IFC4 walls have one more attribute PredefinedType:
assert typeDict["IfcWall"] == ('GlobalId', 'OwnerHistory', 'Name', 'Description', 'ObjectType', 'ObjectPlacement', 'Representation', 'Tag', 'PredefinedType')
Alternatively if using v0.6 you will have to change more in the script. Maybe like in this updated Gist. There was another issue further down and you might encounter more. If in doubt, try to contact the original author or use the script as an inspiration to write your own conversion.

Inserting implementation version to manifest using sbt

I saw here
that it is possible to manually insert specific fields to the manifest:
name := "project"
version := "2.3.5"
packageOptions := Seq(Package.ManifestAttributes(
("Implementation-Version", "2.3.5")))
I would like to use version directly, without recopying the version number.
Putting version instead of "2.3.5" gives an error. Can I somehow use version directly, without recopying the version number?
Get the value of a setting by calling .value on it like so
packageOptions := Seq(
Package.ManifestAttributes(("Implementation-Version", version.value))
)
In general, value can be called in the following scenarios:
value can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting."

Sqlite (within SqliteStudio): invalid command name "parray"

I am discovering writing functions in TCL for Sqlite (https://github.com/pawelsalawa/sqlitestudio/wiki/ScriptingTcl).
I wanted to play a basic exemple found in the official page of sqlite(http://sqlite.org/tclsqlite.html):
db eval {SELECT * FROM MyTable ORDER BY MyID} values {
parray values
puts ""
}
I get the following error:
Error while requesting the database « -- » : invalid command name "parray"
Help is very welcome :)
SqliteStudio does not seem to fully initialise Tcl, as you would expect it from a non-embedded installation:
Using external Tcl packages or modules is not possible, because Tcl
interpreters are not initialized with "init.tcl".
See Wiki.
Background
Standard Tcl sources init.tcl, early as part of an Tcl interpreter's initialisation. init.tcl, in turn, registers a number of Tcl procs for autoloading. parray is one of those lazily acquired procs.
Ways forward
I am not familiar with SqliteStudio. Why not stick with sqlite's standard Tcl frontend, which gives you full Tcl and comes with Tcl distributions free house? But this certainly depends on your requirements.
That said, you could attempt to force-load init.tcl in SqliteStudio's embedded Tcl, but I don't know (and can't test) whether the distribution has not pruned these scripts or whether they were effectively relocated. From the top of my head (untested):
source [file join $tcl_library init.tcl]
# ...
db eval {SELECT * FROM MyTable ORDER BY MyID} values {
parray values
puts ""
}

ORA-00907: missing right parenthesis, on Oracle 10 and not on Oracle 11

Why the following query fails on Oracle 10 an not on Oracle 11.
SELECT trunc(DBMS_RANDOM.value(low => 10, high =>50)) from dual;
Oracle 10:
ORA-00907: missing right parenthesis
This answer is a bit speculative, but one possible explanation for the missing right parentheses error is that this error is not really about missing parentheses. Instead, if the API for DBMS_RANDOM.value is different in your version of Oracle 10 vs. Oracle 11 then you could be seeing this error. Try this query instead:
SELECT TRUNC(DBMS_RANDOM.value(10, 50))
FROM dual
If this works, then you will know that the API has changed between Oracle 10 and 11.
Here is a reference which uses the API as I have in my query.
This was a new feature in 11gR1:
Beginning in this release, it is now possible to invoke the function
in a SQL statement. For example, named notation syntax is:
SELECT f(pn=>3, p2=>2, p1=>1) FROM dual
Or, mixed notation is:
SELECT f(1, pn=>3) FROM dual
In previous releases, attempting named or mixed notation resulted in
an error.
So prior to 11g you could only call a PL/SQL function from SQL using positional notation, e.g.
SELECT trunc(DBMS_RANDOM.value(10, 50)) from dual;
... as #TimBiegeleisen has already shown works. The 'missing right parenthesis' error doesn't necessarily mean your parentheses are unbalanced; just that the parser saw something it didn't expect where it thought a parenthesis might go - in this case, at the =>.

How do I find/use op:except with the multiple xml files?

How do I find/use op:except with the multiple xml files?
I've gotten the nodes from file 1 and file 2, and in the xquery expression I'm tring to find the op:except of those two. When I use op:except, I end up getting an empty set.
XML File 1:
<a>txt</a>
<a>txt2</a>
<a>txt3</a>
XML File 2:
<a>txt2</a>
<a>txt4</a>
<a>txt3</a>
I want output from op:($nodesfromfile1, $nodesfromfile2) to be:
<a>txt</a>
It effectively comes down to the single line behind the return in the following code. You could put that in a function if you like, but it is already very dense, so maybe not worth it..
let $file1 := (
<a>txt</a>,
<a>txt2</a>,
<a>txt3</a>
)
let $file2 := (
<a>txt2</a>,
<a>txt4</a>,
<a>txt3</a>
)
return
$file1[not(. = $file2)]
Note, you also have the 'except' keyword ($file1 except $file2), but that works on node identity which won't work if the nodes comes from different files.
By the way, above code uses string-equality for comparison. If you would prefer to do a comparison on full node-structure, you could also use the deep-equal() function.
HTH!

Resources