equal
deleted
inserted
replaced
75 Py_Initialize(); |
75 Py_Initialize(); |
76 |
76 |
77 if (arguments.size() == 2) { |
77 if (arguments.size() == 2) { |
78 relationNameRegEx = wregex(arguments[0]); |
78 relationNameRegEx = wregex(arguments[0]); |
79 pythonCode = arguments[1]; |
79 pythonCode = arguments[1]; |
|
80 // TODO: allow relation structure changes: if there are more arguments, the describe the output relation |
|
81 // TODO: allow also other modes: |
|
82 // - insert additional records |
|
83 // - process whole relation at once (can do e.g. some aggregations) |
|
84 // - process whole stream at once (can do e.g. some joins or unions) |
80 } else { |
85 } else { |
81 PyMem_RawFree(pythonProgramName); |
86 PyMem_RawFree(pythonProgramName); |
82 throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <pythonCode>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
87 throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <pythonCode>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
83 } |
88 } |
84 } |
89 } |
117 |
122 |
118 pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ? |
123 pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ? |
119 pyDict = PyModule_GetDict(pyModule); |
124 pyDict = PyModule_GetDict(pyModule); |
120 |
125 |
121 for (int i = 0; i < currentRecord.size(); i++) { |
126 for (int i = 0; i < currentRecord.size(); i++) { |
|
127 // TODO: pass particular data-types to Python, not only strings |
122 PyObject* pyValue = PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()); |
128 PyObject* pyValue = PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()); |
123 PyList_SetItem(pyRecord, i, pyValue); |
129 PyList_SetItem(pyRecord, i, pyValue); |
124 string_t attributeName = currentWriterMetadata[i].attributeName; |
130 string_t attributeName = currentWriterMetadata[i].attributeName; |
125 if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED) && !regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) { |
131 if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED) && !regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) { |
126 PyDict_SetItemString(pyDict, convertor.to_bytes(attributeName).c_str(), pyValue); |
132 PyDict_SetItemString(pyDict, convertor.to_bytes(attributeName).c_str(), pyValue); |