0

I am trying to set up a project with autoNumbered predicates. I couldn't use the lang:autoNumbered option in .logic files as it gave me the error that it expected a constraint or a lang:ordered.

So I rewrote my code in a .lb file, which worked. The code is as follows:

create --unique

addblock <doc>
  node(n), node_id(n:id) -> int(id).
  lang:autoNumbered(`node_id).

  cons_node[] = n -> node(n).
  lang:constructor(`cons_node).

  node_has_label[l] = n -> string(l), node(n).
  node_attribute[n, k] = v -> node(n), string(k), string(v).

  node_attribute_id(id, att, val) <- node_id(n: id), node_attribute[n, att] = val.
</doc>

exec <doc>
  +node(n), +cons_node[] = n,
  +node_attribute[n, "label"] = "Person",
  +node_attribute[n, "name"] = "Alice".
</doc>

echo --- node_att_table:
print node_attribute_id

close --destroy

Now I want to move this into a node.logic and a separate data file. How do I do this while keeping the lang:autoNumbered and lang:constructor commands?

EDIT:

This is the code that I have tried to run:

block(`node) {
  export(`{
    node(n), node_id(n:id) -> int(id).
    lang:autoNumbered(`node_id).

    cons_node[] = n -> node(n).
    lang:constructor(`cons_node).

    node_attribute(n, k; v) -> node(n), string(k), string(v).
  })
} <-- .

And I get the error

error parsing block: expected a constraint or lang:ordering pragma (Error BLOCK_PARSE)

on the lang:autoNumbered and lang:constructor lines when I run lb config && make.

Extra info: I use Vagrant to run logicblox and am basing my examples on these blogs: https://developer.logicblox.com/2014/01/structuring-and-compiling-logicblox-applications/

1 Answers1

0

I'm not sure what your original problem was, but this actually should work fine :). You should be able to put the logic in a .logic file and use the addblock --file option. The same applies to the exec logic. Using the tags versus separate files is basically equivalent. This should be identical to including it inline as you did there. If you want to load the data as a csv file, then this should work: https://developer.logicblox.com/content/docs4/core-reference/webhelp/predicates.html#file-predicates

Maybe you earlier tried it from the command-line and the back-tick caused some issues due to its special meaning in shell?

  • I have edited my question to explain in more detail what I try to do and what the problem is. – D. Miedema Jul 27 '17 at 12:38
  • Ah, got it! I believe the lang:constructor and lang:autoNumbered declarations need to go in the 'clauses' section. The 'exports' section is for the public interface of the block. You're not required to use separate compilation and modules btw, you can also just create standalone .logic files with modules. For small projects, this will be fine and you wouldn't really run into naming problems. – Martin Bravenboer Jul 27 '17 at 16:10