#NEWLINE# def test_prepare_hql_query( self ) : #NEWLINE# #INDENT# statement = 'SELECT myUpper(description) FROM sample_07 LIMIT 10' #NEWLINE# snippet_json = ( '\n        {\n            "status": "running",\n            "database": "default",\n            "properties": {\n                "files": [],\n                "functions": [{\n                    "class_name": "org.hue.udf.MyUpper",\n                    "name": "myUpper"\n                }],\n                "settings": []\n            },\n            "result": {\n                "handle": {\n                    "log_context": null,\n                    "statements_count": 1,\n                    "statement_id": 0,\n                    "has_more_statements": false,\n                    "secret": "UVZXF/qtTQumumz0Q8tNDQ==",\n                    "has_result_set": true,\n                    "operation_type": 0,\n                    "modified_row_count": null,\n                    "guid": "ZxOd4IjqTeK1PUTq+MdcDA=="\n                },\n                "type": "table",\n                "id": "ae81b805-dcf1-9692-0452-797681e997ed"\n            },\n            "statement": "%(statement)s",\n            "type": "hive",\n            "id": "9b50e364-f7b2-303d-e924-db8b0bd9866d"\n        }\n    ' % { #NEWLINE# #INDENT# 'statement' : statement , #NEWLINE# #UNINDENT# } ) #NEWLINE# session_json = '\n            {\n                "type": "hive",\n                "properties": [\n                    {\n                        "multiple": true,\n                        "value": [\n                            {\n                                "path": "/user/test/myudfs.jar",\n                                "type": "jar"\n                            }\n                        ],\n                        "nice_name": "Files",\n                        "key": "files",\n                        "help_text": "Add one or more files, jars, or archives to the list of resources.",\n                        "type": "hdfs-files"\n                    },\n                    {\n                        "multiple": true,\n                        "value": [\n                            {\n                                "class_name": "org.hue.udf.MyUpper",\n                                "name": "myUpper"\n                            }\n                        ],\n                        "nice_name": "Functions",\n                        "key": "functions",\n                        "help_text": "Add one or more registered UDFs (requires function name and fully-qualified class name).",\n                        "type": "functions"\n                    },\n                    {\n                        "multiple": true,\n                        "value": [\n                            {\n                                "value": "spark",\n                                "key": "hive.execution.engine"\n                            }\n                        ],\n                        "nice_name": "Settings",\n                        "key": "settings",\n                        "help_text": "Hive and Hadoop configuration properties.",\n                        "type": "settings",\n                        "options": [\n                            "hive.map.aggr",\n                            "hive.exec.compress.output",\n                            "hive.exec.parallel",\n                            "hive.execution.engine",\n                            "mapreduce.job.queuename"\n                        ]\n                    }\n                ],\n                "id": 30\n            }\n    ' #NEWLINE# snippet = json . loads ( snippet_json ) #NEWLINE# session = json . loads ( session_json ) #NEWLINE# hql_query = self . api . _prepare_hql_query ( snippet , statement , session ) #NEWLINE# assert_equal ( [ { #NEWLINE# #INDENT# 'key' : 'hive.execution.engine' , #NEWLINE# 'value' : 'spark' , #NEWLINE# #UNINDENT# } ] , hql_query . settings ) #NEWLINE# assert_equal ( [ { #NEWLINE# #INDENT# 'type' : 'jar' , #NEWLINE# 'path' : '/user/test/myudfs.jar' , #NEWLINE# #UNINDENT# } ] , session_json . file_resources ) #NEWLINE# assert_equal ( [ { #NEWLINE# #INDENT# 'name' : 'myUpper' , #NEWLINE# 'class_name' : 'org.hue.udf.MyUpper' , #NEWLINE# #UNINDENT# } ] , hql_query . functions ) #NEWLINE# config_statements = ', ' . join ( hql_query . get_configuration_statements ( ) ) #NEWLINE# pattern = re . compile ( 'ADD JAR hdfs://[A-Za-z0-9.:_-]+/user/test/myudfs.jar' ) #NEWLINE# assert_true ( pattern . search ( config_statements ) , config_statements ) #NEWLINE# assert_true ( ( "CREATE TEMPORARY FUNCTION myUpper AS 'org.hue.udf.MyUpper'" in config_statements ) , config_statements )