Exemple #1
0
def generateFilterByPredicate(predicateStr, convIdxL, globalNamespace, localNamespace):
    """
    predicateStr :: str
        Predicate string.
        After evaled, predicate type must be (*xs -> bool).
    convIdxL :: [(str -> ANY), int]
        Column index list with type converter.
    globalNamespace :: dict
        Global name space.
    localNamespace :: dict
        local name space.
    return :: tuple(str) -> bool
        Filter function.

    """
    predicate = eval(predicateStr, globalNamespace, localNamespace)
    project1 = pysows.generateProjectConv(convIdxL)

    def filterByPredicate(rec):
        """
        rec :: tuple(str)
        return :: bool

        """
        return predicate(*project1(rec))
    return filterByPredicate
Exemple #2
0
def doMain():
    args = parseOpts(sys.argv[1:])

    g = globals()
    l = locals()
    pysows.loadPythonCodeFile(args.load_file, g, l)
    mapFunc = eval(args.map_func, g, l)
    constructor = eval(args.record_constructor, g, l)

    convIdxL = pysows.getTypedColumnIndexList(args.group_indexes)
    assert len(convIdxL) > 0
    getKeyFromRec = pysows.generateProjectConv(convIdxL)

    reader = pysows.recordReader(sys.stdin, args.separator)

    for rec in reader:
        key = getKeyFromRec(rec)
        mapped = mapFunc(*key)
        outRec = constructor(rec, mapped)
        pysows.printList(outRec)
        print