Exemple #1
0
def getSelectQuery(dss_function, inputTables, config):
    json_file = queryutility.getJson(dss_function.get('name', ''))
    outTableClauses = getOutClause(dss_function, json_file, inputTables)     
    argumentClauses = getArgumentClauses(dss_function, json_file, inputTables)
    if(outTableClauses == '\n'):
        outTableClauses = ''
    if(argumentClauses == '\n'):
        argumentClauses = ''
    
    completeClause = 'USING ' + outTableClauses + argumentClauses
    fullUsingClause = (outTableClauses or argumentClauses) and completeClause
    
    if outTableClauses or argumentClauses:
        print('Running Output Table Clauses')
    
    # Removing partnerFunction functionality due to removal of coprocessor.
    # #TODO ADD USING CLAUSE SOMEWHERE    
    # # Update to:
    # # Following code might have issues with Reduce functions with multiple INPUT TABLES
    # if dss_function.get('hasPartnerFunction', False):
    #     jsonfilePartner= queryutility.getJson(dss_function.get('name',''), dss_function.get('useCoprocessor',''))        
    #     outTableClausesPartner = getOutClause(dss_function['partnerFunction'], jsonfilePartner, inputTables)     
    #     argumentClausesPartner = getArgumentClauses(dss_function['partnerFunction'], jsonfilePartner, inputTables)
    #     if(outTableClausesPartner == '\n'):
    #         outTableClausesPartner = ''
    #     if(argumentClausesPartner == '\n'):
    #         argumentClausesPartner = ''
    #     completeClausePartner = 'USING ' + outTableClausesPartner + argumentClausesPartner
    #     fullUsingClausePartner = (outTableClausesPartner or argumentClausesPartner) and completeClausePartner
        

    #     mapQuery = MAP_FUNCTION_QUERY.format(getFunctionName(config, dss_function, useCoprocessor),                       
    #                    getOnClause(dss_function, jsonfile, inputTables),
    #                    fullUsingClause)
    #     return MR_SELECT_QUERY.format(dss_function.get('select_clause', '*'),
    #                    getFunctionName(config, dss_function['partnerFunction'], useCoprocessor),                       
    #                    mapQuery, 
    #                    "",
    #                    getPartitionByMap(dss_function['partnerFunction']['required_input'][0]), getOrderByMap(dss_function['partnerFunction']['required_input'][0]),
    #                    fullUsingClausePartner,
    #                    getAdditionClauses(dss_function['partnerFunction']))
    # else:
    #     return SELECT_QUERY.format(dss_function.get('select_clause', '*'),
    #                    getFunctionName(config, dss_function),                       
    #                    getOnClause(dss_function, jsonfile, inputTables),
    #                    fullUsingClause,
    #                    getAdditionClauses(dss_function))
    return SELECT_QUERY.format(dss_function.get('select_clause', '*'),
                       getFunctionName(config, dss_function),                       
                       getOnClause(dss_function, json_file, inputTables),
                       fullUsingClause,
                       getAdditionClauses(dss_function))
def getSelectQuery(dss_function, inputTables):

    # query, not yet supporting partition by and order by clauses from recipe settings,
    # but not needed for naiveBayes
    query = ""
    cascadedFunctions = dss_function['cascaded_functions']
    if 0 < len(cascadedFunctions):
        cquery = ""
        selectedInputTable = inputTables[0] if (
            0 == len(dss_function['unaliased_inputs']['values'])
        ) else dss_function['unaliased_inputs']['values'][0]
        inputInfo = next(x.tablename for x in inputTables
                         if x.datasetname == selectedInputTable)
        for fun in cascadedFunctions:
            cpartitionBy = ""
            if 'partitionBy' in fun:
                cpartitionByNode = fun['partitionBy']
                if not cpartitionByNode['isSetByUser']:
                    cpartitionBy = "PARTITION BY {}".format(
                        cpartitionByNode['key'])
            corderBy = ""
            if 'orderBy' in fun:
                corderByNode = fun['orderBy']
                if not corderByNode['isSetByUser']:
                    corderBy = "ORDER BY {}".format(corderByNode['key'])
            carguments = ""
            jsonFunction = queryutility.getJson(fun.get('name', ''))
            if 'arguments_clauses' in fun:
                cargumentslist = [
                    n for n in dss_function['arguments']
                    if n.get('name', "").upper() in fun['arguments_clauses']
                ]
                carguments += queryutility.getJoinedArgumentsString(
                    cargumentslist,
                    queryutility.getArgumentClausesFromJson(jsonFunction))
            if 'arguments_nonuserdefined' in fun:
                carguments += queryutility.getJoinedArgumentsString(
                    fun['arguments_nonuserdefined'],
                    queryutility.getArgumentClausesFromJson(jsonFunction))
            cfunction = fun.get('name', "")
            cquery = """SELECT * FROM {cfunction} (ON {inputInfo} {cpartitionBy} {corderBy} {carguments})""".format(
                cfunction=cfunction,
                inputInfo=inputInfo,
                cpartitionBy=cpartitionBy,
                corderBy=corderBy,
                carguments=carguments)
            inputInfo = """({cquery})""".format(cquery=cquery)
        query = inputInfo + ';'
    return query
Exemple #3
0
def getSelectQuery(dss_function, inputTables):
    jsonfile = queryutility.getJson(dss_function.get('name', ''))
    return SELECT_QUERY.format(
        dss_function.get('name', ''),
        getOnClause(dss_function, jsonfile, inputTables),
        getArgumentClauses(dss_function, jsonfile, inputTables))