Beispiel #1
0
IHqlExpression * addOutput(IHqlExpression * dataset)
{
    return createValue(no_output, makeVoidType(), LINK(dataset));
}
Beispiel #2
0
//MORE: Really this should create no_selects for the sub records, but pass on that for the moment.
void DataSourceMetaData::gatherFields(IHqlExpression * expr, bool isConditional)
{
    switch (expr->getOperator())
    {
    case no_record:
        gatherChildFields(expr, isConditional);
        break;
    case no_ifblock:
        {
            OwnedITypeInfo boolType = makeBoolType();
            OwnedITypeInfo voidType = makeVoidType();
            isStoredFixedWidth = false;
            fields.append(*new DataSourceMetaItem(FVFFbeginif, NULL, NULL, boolType));
            gatherChildFields(expr->queryChild(1), true);
            fields.append(*new DataSourceMetaItem(FVFFendif, NULL, NULL, voidType));
            break;
        }
    case no_field:
        {
            if (expr->hasProperty(__ifblockAtom))
                break;
            Linked<ITypeInfo> type = expr->queryType();
            IAtom * name = expr->queryName();
            IHqlExpression * nameAttr = expr->queryProperty(namedAtom);
            StringBuffer outname;
            if (nameAttr && nameAttr->queryChild(0)->queryValue())
                nameAttr->queryChild(0)->queryValue()->getStringValue(outname);
            else
                outname.append(name).toLowerCase();

            StringBuffer xpathtext;
            const char * xpath = NULL;
            IHqlExpression * xpathAttr = expr->queryProperty(xpathAtom);
            if (xpathAttr && xpathAttr->queryChild(0)->queryValue())
                xpath = xpathAttr->queryChild(0)->queryValue()->getStringValue(xpathtext);

            if (isKey() && expr->hasProperty(blobAtom))
                type.setown(makeIntType(8, false));
            type_t tc = type->getTypeCode();
            if (tc == type_row)
            {
                OwnedITypeInfo voidType = makeVoidType();
                fields.append(*new DataSourceMetaItem(FVFFbeginrecord, outname, xpath, voidType));
                gatherChildFields(expr->queryRecord(), isConditional);
                fields.append(*new DataSourceMetaItem(FVFFendrecord, outname, xpath, voidType));
            }
            else if ((tc == type_table) || (tc == type_groupedtable))
            {
                isStoredFixedWidth = false;
                fields.append(*new DataSourceDatasetItem(outname, xpath, expr));
            }
            else if (tc == type_set)
            {
                isStoredFixedWidth = false;
                fields.append(*new DataSourceSetItem(outname, xpath, type));
            }
            else
            {
                if (type->getTypeCode() == type_alien)
                {
                    IHqlAlienTypeInfo * alien = queryAlienType(type);
                    type.set(alien->queryPhysicalType());
                }
                addSimpleField(outname, xpath, type);
            }
            break;
        }
    }
}
Beispiel #3
0
IHqlExpression * PositionTransformer::createTransformed(IHqlExpression * _expr)
{
    OwnedHqlExpr transformed = NewHqlTransformer::createTransformed(_expr);

    switch (transformed->getOperator())
    {
    case no_table:
        {
            IHqlExpression * mode = transformed->queryChild(2);
            HqlExprArray fields;
            HqlExprArray args;

            if (mode->getOperator() == no_thor)
            {
                unwindChildren(fields, transformed->queryChild(1));
                IHqlExpression * filePosAttr = createComma(createAttribute(virtualAtom, createAttribute(filepositionAtom)), insertedAttr.getLink());
                IHqlExpression * sizeofAttr = createComma(createAttribute(virtualAtom, createAttribute(sizeofAtom)), insertedAttr.getLink());
                fields.append(*createField(fileposName, makeIntType(8, false), NULL, filePosAttr));
                fields.append(*createField(recordlenName, makeIntType(2, false), NULL, sizeofAttr));

                unwindChildren(args, transformed);
                args.replace(*createRecord(fields), 1);
                return transformed->clone(args);
            }
        }
        break;
    case no_iterate:
    case no_hqlproject:
        {
            HqlExprArray args;
            HqlExprArray assigns;
            IHqlExpression * transform = transformed->queryChild(1);
            unwindChildren(args, transformed);
            unwindChildren(assigns, transform);
            IHqlExpression * inRecord = transformed->queryChild(0)->queryRecord();
            IHqlExpression * outRecord = transform->queryRecord();

            HqlExprArray fields;
            unwindChildren(fields, outRecord);
            ForEachChild(idx, inRecord)
            {
                IHqlExpression * child = inRecord->queryChild(idx);
                if (child->hasProperty(insertedAtom))
                {
                    IHqlExpression * newTarget = createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink());
                    fields.append(*newTarget);
                    assigns.append(*createValue(no_assign, makeVoidType(), newTarget, createSelectExpr(createValue(no_left), LINK(newTarget))));
                }
            }
            IHqlExpression * newRecord = createRecord(fields);
            args.replace(*createValue(no_transform, newRecord->getType(), assigns), 1);
            return transformed->clone(args);
        }
        break;
    case no_join:
        //only ok if join first
    case no_rollup:
    case no_newaggregate:
    case no_aggregate:
        fail();
        break;
    case no_usertable:
    case no_selectfields:
        {
            IHqlExpression * grouping = transformed->queryChild(2);
            if (grouping && (grouping->getOperator() != no_attr))
                fail();
            IHqlExpression * record = transformed->queryRecord();
            HqlExprArray fields;
            unwindChildren(fields, transformed->queryChild(1));
            ForEachChild(idx, record)
            {
                IHqlExpression * child = record->queryChild(idx);
                if (child->hasProperty(insertedAtom))
                    fields.append(*createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink()));
            }

            HqlExprArray args;
            unwindChildren(args, transformed);
            args.replace(*createRecord(fields), 1);
            return transformed->clone(args);
        }
Beispiel #4
0
//MORE: Really this should create no_selects for the sub records, but pass on that for the moment.
void DataSourceMetaData::gatherFields(IHqlExpression * expr, bool isConditional, bool *pMixedContent)
{
    switch (expr->getOperator())
    {
    case no_record:
        gatherChildFields(expr, isConditional, pMixedContent);
        break;
    case no_ifblock:
        {
            OwnedITypeInfo boolType = makeBoolType();
            OwnedITypeInfo voidType = makeVoidType();
            isStoredFixedWidth = false;
            fields.append(*new DataSourceMetaItem(FVFFbeginif, NULL, NULL, boolType));
            gatherChildFields(expr->queryChild(1), true, pMixedContent);
            fields.append(*new DataSourceMetaItem(FVFFendif, NULL, NULL, voidType));
            break;
        }
    case no_field:
        {
            if (expr->hasAttribute(__ifblockAtom))
                break;
            Linked<ITypeInfo> type = expr->queryType();
            IAtom * name = expr->queryName();
            IHqlExpression * nameAttr = expr->queryAttribute(namedAtom);
            StringBuffer outname;
            if (nameAttr && nameAttr->queryChild(0)->queryValue())
                nameAttr->queryChild(0)->queryValue()->getStringValue(outname);
            else
                outname.append(name).toLowerCase();

            StringBuffer xpathtext;
            const char * xpath = NULL;
            IHqlExpression * xpathAttr = expr->queryAttribute(xpathAtom);
            if (xpathAttr && xpathAttr->queryChild(0)->queryValue())
                xpath = xpathAttr->queryChild(0)->queryValue()->getStringValue(xpathtext);
            unsigned flag = FVFFnone;
            if (isKey() && expr->hasAttribute(blobAtom))
            {
                type.setown(makeIntType(8, false));
                flag = FVFFblob;
            }
            type_t tc = type->getTypeCode();
            if (tc == type_row)
            {
                OwnedITypeInfo voidType = makeVoidType();
                Owned<DataSourceMetaItem> begin = new DataSourceMetaItem(FVFFbeginrecord, outname, xpath, voidType);
                //inherit mixed content from child row with xpath('')
                bool *pItemMixedContent = (pMixedContent && xpath && !*xpath) ? pMixedContent : &(begin->hasMixedContent);
                fields.append(*begin.getClear());
                gatherChildFields(expr->queryRecord(), isConditional, pItemMixedContent);
                fields.append(*new DataSourceMetaItem(FVFFendrecord, outname, xpath, voidType));
            }
            else if ((tc == type_dictionary) || (tc == type_table) || (tc == type_groupedtable))
            {
                isStoredFixedWidth = false;
                Owned<DataSourceDatasetItem> ds = new DataSourceDatasetItem(outname, xpath, expr);
                if (pMixedContent && xpath && !*xpath)
                    *pMixedContent = ds->queryChildMeta()->hasMixedContent;
                fields.append(*ds.getClear());
            }
            else if (tc == type_set)
            {
                isStoredFixedWidth = false;
                if (pMixedContent && xpath && !*xpath)
                    *pMixedContent = true;
                fields.append(*new DataSourceSetItem(outname, xpath, type));
            }
            else
            {
                if (type->getTypeCode() == type_alien)
                {
                    IHqlAlienTypeInfo * alien = queryAlienType(type);
                    type.set(alien->queryPhysicalType());
                }
                if (pMixedContent && xpath && !*xpath)
                    *pMixedContent = true;
                addSimpleField(outname, xpath, type, flag);
            }
            break;
        }
    }
}