is it possible to assign dynamic value from request-path to `table` attribute for FormHandler gramex-config entry? - gramex

ref to FormHandler-param-doc
below is the sample gramex-config snippet:
dburl: postgresql://$db_name:$db_name#localhost:5432/$db_name
data_filter:
pattern: /$YAMLURL/data_filter/(\w+)
handler: FormHandler
kwargs:
url: $dburl
table: {_0}
modify: data_filter.by_month_date(data)
Is it possible to assign value dynamically for table attribute from part of request-URL path?
for a sample request like:
/data_filter/prod_rec_20?S_CODE=20&D_CODE=322&Market_Code=10753&Crop_Code=106
Getting the below error:
Traceback (most recent call last):
File "c:\programdata\anaconda3\lib\site-packages\gramex\handlers\formhandler.py", line 157, in get
result[key] = yield val
File "c:\programdata\anaconda3\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "c:\programdata\anaconda3\lib\concurrent\futures\_base.py", line 425, in result
return self.__get_result()
File "c:\programdata\anaconda3\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
File "c:\programdata\anaconda3\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "c:\programdata\anaconda3\lib\site-packages\gramex\data.py", line 247, in filter
raise ValueError('No table: or query: specified')
ValueError: No table: or query: specified

Sure. Please see https://learn.gramener.com/guide/formhandler/#formhandler-parameters
You can specify table: '{_0}'. Then /data_filter/?table=prod_rec_20 would work.
table: {_0} without the quotes won't work, though. YAML interprets the {} as an object. You need to quote the '{_0}' for this to work. (I tested it, and it's working fine.

Related

Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure `apoc.do.when`: Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxExcepti

Can someone please help me with my probelm.
When i execute the below cypher query im getting exception as in the Title:
LOAD CSV WITH HEADERS FROM "file:///MNK/device.csv" AS line
MATCH (rSeq:Sequence{key:"runId_seq"})
OPTIONAL MATCH (l:Location{siteGaid:line.location_key}) WHERE NOT l:Model
WITH count(l) as i, line.location_key as key,line.location_key as sourceobjectId,
timestamp() as createdate,rSeq.runId as runId
CALL apoc.do.when(
i = 0,
'CREATE (a:locationServiceMigrationError
{errorCode: "missing_location",
errorDescription: "unable to find Location by its key",
matchingObjectKey: key,
srcObjectId: sourceobjectId,
type:"Location",
srcObjectName: "location_key",
sourceFileName: "device.csv",
scriptName:"device.cql",
createdDate:createdate,
runId:runId
}) RETURN a AS node',
'RETURN 0 AS result',
{key:key,
sourceobjectId:sourceobjectId,
createdate:createdate}
) YIELD value
RETURN count(value);
...Getting Error message like below
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure apoc.do.when: Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Variable runId not defined (line 11, column 11 (offset: 463))
...When i tried changing the 1st line with different file name as below then it is going fine.
LOAD CSV WITH HEADERS FROM "file:///MNK/location_coordinate_service.csv" AS line
.. Im not able to understand what exactly the issue is .
runId has to be passed into the parameter list too,
...,
{
key:key,
sourceobjectId:sourceobjectId,
createdate:createdate,
runId: runId
}

JMeter,JDBC Request,Stored Procedure,Oracle

i need to call this PL\SQL function structured like this:
FUNCTION FunctionName ( p_lang_IN IN SESSIONS.s_lang%TYPE,
p_user_IN IN VARCHAR2,
p_pwd_IN IN VARCHAR2,
p_source_IN IN SESSION_SOURCE.ss_userid%TYPE,
p_sessionstring_OUT OUT SESSIONS.s_id%TYPE,
p_pwd_type IN NUMBER DEFAULT 0,
P_PSWD_STATUS OUT NUMBER
)
RETURN NUMBER;
I'm using a JDBC Request created like this:
enter image description here
I get the following error:
ORA-06550: line 1, column 7:
PLS-00221: 'FunctionName' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I suppose an error in the syntax of the call ... but that is?
Thanks in advance
Bye

how to fix: attempt to index global "f" (a nil value), LUA I/O text editing

As title says that error appears when executing the following code.
//open the file
local out = io.open('path', 'r')
//Fetch all lines and add them to a table
local lines = {}
for line in f:lines() do
table.insert(lines, line)
end
//close
out:close()
//insert line
table.insert(lines, 8, "test this bullshit\n")
//temporary file
local out = io.open('pathnew', 'w')
for _, line in ipairs(lines) do
out:write(line)
end
//close temporary
out:close()
//delete old file (from the first io.open)
os.remove('pathold')
//rename temporary file to the old one (from the first io.open)
os.rename('pathnew', 'pathold')
You are opening a file you call out but then try to read lines from a file you call f. f doesn’t exist.

Edit specific line in a file with lua

I'm trying to edit a specific line in a file using lua.
For example, I have a file with 12 lines. I want to edit the 2nd line ONLY.
Line 1: Hello
Line 2: Hello again
The output file would be for example
Line 1: Hello
Line 2: Whatever
but without caring what's the content of the 2nd line. Just by the number of the line.
I figured it out after all. Here's the code:
function Initialize()
inputFile = 'PathToFile'
end
function Edit()
local file = io.open(inputFile, 'r')
local fileContent = {}
for line in file:lines() do
table.insert (fileContent, line)
end
io.close(file)
fileContent[3] = 'This line has been edited'
file = io.open(inputFile, 'w')
for index, value in ipairs(fileContent) do
file:write(value..'\n')
end
io.close(file)
end

django reverse foreign key on admin list_display fails

I'm tring to display a reverse foreign key on admin list_change:
# models.py
class Person(models.Model):
id = models.CharField(max_length=50, primary_key=True)
class Book(models.Model):
person = models.ForeignKey(Person, related_name='samples')
name = models.CharField(max_length=50)
#admin.py
#admin.register(Person)
class PersonAdmin(CustomAdmin):
list_display = ('id', 'links')
def links(self, obj):
links = obj.book_set().all()
return mark_safe('<br/>'.join(links))
It's like this other post
I'm using django 1.8 and it fails:
Stacktrace:
File "/venv/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 320, in result_list
'results': list(results(cl))}
File "/venv/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 296, in results
yield ResultList(None, items_for_result(cl, res, None))
File "/venv/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 287, in __init__
super(ResultList, self).__init__(*items)
File "/venv/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 199, in items_for_result
f, attr, value = lookup_field(field_name, result, cl.model_admin)
File "/venv/lib/python2.7/site-packages/django/contrib/admin/utils.py", line 278, in lookup_field
value = attr(obj)
File "/home/kparsa/boom/myapp/myapp/admin.py", line 299, in links
link = obj.book_set().all()
File "/venv/lib/python2.7/site-packages/django/db/models/fields/related.py", line 691, in __call__
manager = getattr(self.model, kwargs.pop('manager'))
KeyError: u'manager'
Does anyone know how to get this to work properly?
Note that I do NOT want to do something like
qres = Book.objects.filter(person__id=obj.id).values_list('id', 'name').order_by('name')
for x, y in qres:
links.append('{}'\
.format(x, y))
because it will run many duplicate queries (# of rows).
The error was the result of the fact that I had used a related_name in the model but instead I was trying to use the default model name.
In order to solve the problem of the duplicate queries, I queried for all the results in get_queryset(), stored the results in memcached, then in the "links" method, I just pulled it from the cache.
Works great!
The only danger here would be getting out of sync when new data is pushed. I put a 100 second timeout on the cache to avoid issues.

Resources