DataTypePtr recursiveRemoveLowCardinality(const DataTypePtr & type)
{
    if (!type)
        return type;

    if (const auto * array_type = typeid_cast<const DataTypeArray *>(type.get()))
        return std::make_shared<DataTypeArray>(recursiveRemoveLowCardinality(array_type->getNestedType()));

    if (const auto * tuple_type = typeid_cast<const DataTypeTuple *>(type.get()))
    {
        DataTypes elements = tuple_type->getElements();
        for (auto & element : elements)
            element = recursiveRemoveLowCardinality(element);

        if (tuple_type->haveExplicitNames())
            return std::make_shared<DataTypeTuple>(elements, tuple_type->getElementNames());
        else
            return std::make_shared<DataTypeTuple>(elements);
    }

    if (const auto * low_cardinality_type = typeid_cast<const DataTypeLowCardinality *>(type.get()))
        return low_cardinality_type->getDictionaryType();

    return type;
}
		EntityPropertyTypeParserPtr create( const std::string& name, DataTypePtr dataType )
		{
			if ( dataType->typeName().substr(0, 4) == "INT8" ||
				 dataType->typeName().substr(0, 5) == "UINT8" )
				return new EntityIntParser();
			else
				return NULL;
		}
Exemplo n.º 3
0
DataArg::DataArg(const std::string &name, const DataTypePtr &type,
	             size_t elements) : TypeStorage(name, type) {
	_elements=elements;
	_data=(char *)malloc(type->objectSize()*_elements);
//	fprintf(stderr, "malloc %p %s/(%d of %s (%d))\n", _data,
//	        name.c_str(), elements, type->asString().c_str(),
//	        type->objectSize());
	memset(_data, 0, type->objectSize()*_elements);
}
Exemplo n.º 4
0
	void DataTypeManager::load(const std::string& _fileName)
	{
		std::string fileName = MyGUI::DataManager::getInstance().getDataPath(_fileName);
		pugi::xml_document doc;
		pugi::xml_parse_result result = doc.load_file(fileName.c_str());
		if (result)
		{
			pugi::xpath_node_set nodes = doc.select_nodes("Document/DataTypes/DataType");
			for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			{
				DataTypePtr data = DataTypePtr(new DataType());
				data->deserialization((*node).node());
				mDataInfos.push_back(data);
			}
		}
	}
		EntityPropertyTypeParserPtr create( const std::string& name, DataTypePtr dataType )
		{
			if ( dataType->typeName().substr(0, 5) == "ARRAY" )
				return new EntityArrayParser();
			else
				return NULL;
		}
		EntityPropertyTypeParserPtr create( const std::string& name, DataTypePtr dataType )
		{
			if ( dataType->typeName().substr(0, 6) == "STRING" )
				return new EntityStringParser();
			else
				return NULL;
		}
Exemplo n.º 7
0
ColumnPtr FunctionArrayIntersect::castRemoveNullable(const ColumnPtr & column, const DataTypePtr & data_type) const
{
    if (auto column_nullable = checkAndGetColumn<ColumnNullable>(column.get()))
    {
        auto nullable_type = checkAndGetDataType<DataTypeNullable>(data_type.get());
        const auto & nested = column_nullable->getNestedColumnPtr();
        if (nullable_type)
        {
            auto casted_column = castRemoveNullable(nested, nullable_type->getNestedType());
            return ColumnNullable::create(casted_column, column_nullable->getNullMapColumnPtr());
        }
        return castRemoveNullable(nested, data_type);
    }
    else if (auto column_array = checkAndGetColumn<ColumnArray>(column.get()))
    {
        auto array_type = checkAndGetDataType<DataTypeArray>(data_type.get());
        if (!array_type)
            throw Exception{"Cannot cast array column to column with type "
                            + data_type->getName() + " in function " + getName(), ErrorCodes::LOGICAL_ERROR};

        auto casted_column = castRemoveNullable(column_array->getDataPtr(), array_type->getNestedType());
        return ColumnArray::create(casted_column, column_array->getOffsetsPtr());
    }
    else if (auto column_tuple = checkAndGetColumn<ColumnTuple>(column.get()))
    {
        auto tuple_type = checkAndGetDataType<DataTypeTuple>(data_type.get());

        if (!tuple_type)
            throw Exception{"Cannot cast tuple column to type "
                            + data_type->getName() + " in function " + getName(), ErrorCodes::LOGICAL_ERROR};

        auto columns_number = column_tuple->getColumns().size();
        Columns columns(columns_number);

        const auto & types = tuple_type->getElements();

        for (auto i : ext::range(0, columns_number))
        {
            columns[i] = castRemoveNullable(column_tuple->getColumnPtr(i), types[i]);
        }
        return ColumnTuple::create(columns);
    }

    return column;
}
Exemplo n.º 8
0
    std::shared_ptr<FloatValue> FloatValue::Create(DataTypePtr data_type,
                                                   double value) {
        TypeSpecifier type = data_type->GetType();
        if (type == F32 || type == F64) {
            return std::shared_ptr<FloatValue>(new FloatValue(data_type, value));
        }

        return nullptr;
    }
Exemplo n.º 9
0
bool
ValueNode::checkElementTypesRec (const DataTypePtr &dataType,
				 LContext &lcontext,
				 int &eIndex) const
{
    //
    //  recursively iterate through nested structs and arrays
    //  in this data type, checking element types along the way
    //

    assert(eIndex < (int)elements.size());
    if( StructTypePtr structType = dataType.cast<StructType>() )
    {
	for(MemberVectorConstIterator it = structType->members().begin();
	    it != structType->members().end();
	    it++)
	{
	    if(!checkElementTypesRec(it->type, lcontext, eIndex))
		return false;
	}
    }
    else if( ArrayTypePtr arrayType = dataType.cast<ArrayType>() )
    {
	for (int i = 0; i < arrayType->size(); ++i)
	{
	    if( !checkElementTypesRec(arrayType->elementType(), lcontext, eIndex) )
		return false;
	}
    }
    else if (!dataType->canCastFrom (elements[eIndex++]->type))
    {
	string fromType = "unknown";
	if( elements[eIndex-1]->type)
	    fromType = elements[eIndex-1]->type->asString();
	MESSAGE_LE (lcontext, ERR_ARR_EL_TYPE, 
		    elements[eIndex-1]->lineNumber,
		    "Cannot convert the type of value element " 
		    << eIndex-1 << " "
		    "(" << fromType << ") "
		    "to type " << dataType->asString() << ".");
	return false;
    }
    return true;
}
Exemplo n.º 10
0
	DataPtr DataUtility::getSelectedParentDataByType(DataPtr _data, DataTypePtr _info)
	{
		if (_data == nullptr)
			return NULL;

		for (DataType::VectorString::const_iterator child = _data->getType()->getChilds().begin(); child != _data->getType()->getChilds().end(); child ++)
		{
			if ((*child) == _info->getName())
				return _data;
		}

		return getSelectedParentDataByType(_data->getChildSelected(), _info);
	}
Exemplo n.º 11
0
Columns FunctionArrayIntersect::castColumns(
        Block & block, const ColumnNumbers & arguments, const DataTypePtr & return_type,
        const DataTypePtr & return_type_with_nulls) const
{
    size_t num_args = arguments.size();
    Columns columns(num_args);

    auto type_array = checkAndGetDataType<DataTypeArray>(return_type.get());
    auto & type_nested = type_array->getNestedType();
    auto type_not_nullable_nested = removeNullable(type_nested);

    const bool is_numeric_or_string = isNumber(type_not_nullable_nested)
                                      || isDateOrDateTime(type_not_nullable_nested)
                                      || isStringOrFixedString(type_not_nullable_nested);

    DataTypePtr nullable_return_type;

    if (is_numeric_or_string)
    {
        auto type_nullable_nested = makeNullable(type_nested);
        nullable_return_type = std::make_shared<DataTypeArray>(type_nullable_nested);
    }

    const bool nested_is_nullable = type_nested->isNullable();

    for (size_t i = 0; i < num_args; ++i)
    {
        const ColumnWithTypeAndName & arg = block.getByPosition(arguments[i]);
        auto & column = columns[i];

        if (is_numeric_or_string)
        {
            /// Cast to Array(T) or Array(Nullable(T)).
            if (nested_is_nullable)
            {
                if (arg.type->equals(*return_type))
                    column = arg.column;
                else
                    column = castColumn(arg, return_type, context);
            }
            else
            {
                /// If result has array type Array(T) still cast Array(Nullable(U)) to Array(Nullable(T))
                ///  because cannot cast Nullable(T) to T.
                if (arg.type->equals(*return_type) || arg.type->equals(*nullable_return_type))
                    column = arg.column;
                else if (static_cast<const DataTypeArray &>(*arg.type).getNestedType()->isNullable())
                    column = castColumn(arg, nullable_return_type, context);
                else
                    column = castColumn(arg, return_type, context);
            }
        }
        else
        {
            /// return_type_with_nulls is the most common subtype with possible nullable parts.
            if (arg.type->equals(*return_type_with_nulls))
                column = arg.column;
            else
                column = castColumn(arg, return_type_with_nulls, context);
        }
    }

    return columns;
}
Exemplo n.º 12
0
Workflow::ActorPrototype *ScriptWorkerSerializer::string2actor(const QString data, const QString actorName, QString &error, const QString actorFilePath) {
    QDomDocument xml;
    xml.setContent(data,false,&error);
    if(!error.isEmpty()) {
        return NULL;
    }
    QDomElement doc = xml.documentElement();
    DataTypeRegistry *dtr = Workflow::WorkflowEnv::getDataTypeRegistry();
    assert(dtr);

    QDomNodeList inputs = doc.elementsByTagName(IN_SLOT_ELEMENT);
    QList<DataTypePtr> inputTypes;
    for(int i = 0; i < inputs.size(); i++) {
        QDomElement slot = inputs.item(i).toElement();
        QString id = slot.attribute(SLOT_ID);
        inputTypes << dtr->getById(id);
    }

    QDomNodeList outputs = doc.elementsByTagName(OUT_SLOT_ELEMENT);
    QList<DataTypePtr> outputTypes;
    for(int i = 0; i < outputs.size(); i++) {
        QDomElement slot = outputs.item(i).toElement();
        QString id = slot.attribute(SLOT_ID);
        outputTypes << dtr->getById(id);
    }

    QDomNodeList attributes = doc.elementsByTagName(ATTR_ELEMENT);
    QList<Attribute *>attrs;
    for(int i = 0;i < attributes.size(); i++) {
        QDomElement attr = attributes.item(i).toElement();
        QString typeId = attr.attribute(TYPE_ID);
        QString name = attr.attribute(NAME_ID);

        DataTypePtr ptr = dtr->getById(typeId);
        Descriptor desc(name, name, ptr->getDisplayName());
        if(ptr == BaseTypes::BOOL_TYPE()) {
            attrs << new Attribute(desc, ptr, false, QVariant(false));
        }
        else {
            attrs << new Attribute(desc, ptr);
        }
    }

    QString newActorName = actorName;
    if (newActorName.isEmpty()) {
        QDomElement name = doc.elementsByTagName(NAME_ELEMENT).item(0).toElement();
        newActorName = name.attribute(NAME_ID);
    }

    QDomElement descr = doc.elementsByTagName(DESCR_ELEMENT).item(0).toElement();
    QString actorDesc = descr.attribute(DESCR_ID);

    // if actorName is not set then it is not alias name
    bool isAliasName = !actorName.isEmpty();

    Workflow::ActorPrototype *proto = Workflow::IncludedProtoFactory::getScriptProto(inputTypes, outputTypes, attrs, newActorName, actorDesc, actorFilePath, isAliasName);

    if (NULL == proto) {
        error = QObject::tr("UGENE external error. Please, try again");
        return NULL;
    }

    return proto;
}
ColumnPtr recursiveLowCardinalityConversion(const ColumnPtr & column, const DataTypePtr & from_type, const DataTypePtr & to_type)
{
    if (!column)
        return column;

    if (from_type->equals(*to_type))
        return column;

    if (const auto * column_const = typeid_cast<const ColumnConst *>(column.get()))
        return ColumnConst::create(recursiveLowCardinalityConversion(column_const->getDataColumnPtr(), from_type, to_type),
                                   column_const->size());

    if (const auto * low_cardinality_type = typeid_cast<const DataTypeLowCardinality *>(from_type.get()))
    {
        if (to_type->equals(*low_cardinality_type->getDictionaryType()))
            return column->convertToFullColumnIfLowCardinality();
    }

    if (const auto * low_cardinality_type = typeid_cast<const DataTypeLowCardinality *>(to_type.get()))
    {
        if (from_type->equals(*low_cardinality_type->getDictionaryType()))
        {
            auto col = low_cardinality_type->createColumn();
            static_cast<ColumnLowCardinality &>(*col).insertRangeFromFullColumn(*column, 0, column->size());
            return std::move(col);
        }
    }

    if (const auto * from_array_type = typeid_cast<const DataTypeArray *>(from_type.get()))
    {
        if (const auto * to_array_type = typeid_cast<const DataTypeArray *>(to_type.get()))
        {
            const auto * column_array = typeid_cast<const ColumnArray *>(column.get());
            if (!column_array)
                throw Exception("Unexpected column " + column->getName() + " for type " + from_type->getName(),
                                ErrorCodes::ILLEGAL_COLUMN);

            auto & nested_from = from_array_type->getNestedType();
            auto & nested_to = to_array_type->getNestedType();

            return ColumnArray::create(
                    recursiveLowCardinalityConversion(column_array->getDataPtr(), nested_from, nested_to),
                    column_array->getOffsetsPtr());
        }
    }

    if (const auto * from_tuple_type = typeid_cast<const DataTypeTuple *>(from_type.get()))
    {
        if (const auto * to_tuple_type = typeid_cast<const DataTypeTuple *>(to_type.get()))
        {
            const auto * column_tuple = typeid_cast<const ColumnTuple *>(column.get());
            if (!column_tuple)
                throw Exception("Unexpected column " + column->getName() + " for type " + from_type->getName(),
                                ErrorCodes::ILLEGAL_COLUMN);

            Columns columns = column_tuple->getColumns();
            auto & from_elements = from_tuple_type->getElements();
            auto & to_elements = to_tuple_type->getElements();
            for (size_t i = 0; i < columns.size(); ++i)
            {
                auto & element = columns[i];
                element = recursiveLowCardinalityConversion(element, from_elements.at(i), to_elements.at(i));
            }
            return ColumnTuple::create(columns);
        }
    }

    throw Exception("Cannot convert: " + from_type->getName() + " to " + to_type->getName(), ErrorCodes::TYPE_MISMATCH);
}
Exemplo n.º 14
0
void
CallNode::computeType (LContext &lcontext, const SymbolInfoPtr &initInfo)
{
    //
    // Compute the type of a function call.  This is the same type
    // as the function's return type, provided the call is valid.
    //

    //
    // Verify that what we are trying to call is actually a function.
    //

    if (!function)
	return;

    function->computeType (lcontext, initInfo);

    if (!function->type)
	return;

    FunctionTypePtr functionType = function->type.cast <FunctionType>();

    if (!functionType)
    {
	MESSAGE_LE (lcontext, ERR_NON_FUNC, function->lineNumber,
	    "Invalid function call to call non-function "
	    "(" << function->name << " is of type " <<
	    function->type->asString() << ").");

	return;
    }

    //
    // We shouldn't have more function call arguments than parameters.
    //

    const ParamVector &parameters = functionType->parameters();

    if (arguments.size() > parameters.size())
    {
	MESSAGE_LE (lcontext, ERR_FUNC_ARG_NUM, function->lineNumber,
	    "Too many arguments in call to function " << function->name << ".");

	return;
    }

    //
    // Compare the types of the arguments to the call with
    // the types of the function's parameters.
    //

    for (int i = 0; i < (int)parameters.size(); ++i)
    {
	if (i < (int)arguments.size())
	{
	    //
	    // We have a function call argument for parameter i.
	    //

	    arguments[i]->computeType (lcontext, initInfo);

	    TypePtr argType = arguments[i]->type;

	    if (!argType)
		return;

	    DataTypePtr paramType = parameters[i].type;

	    if (parameters[i].isWritable())
	    {
		//
		// output parameter -- argument must be an lvalue
		// of the same type as the parameter
		//

		if (!arguments[i]->isLvalue (initInfo))
		{
		    MESSAGE_LE (lcontext, ERR_FUNC_ARG_LVAL, arguments[i]->lineNumber,
			"Argument " << i+1 << " in call to function " <<
			function->name << " corresponds to an output "
			"parameter but it is not an lvalue.");

		    return;
		}

		if (!paramType->isSameTypeAs (argType))
		{
		    MESSAGE_LE (lcontext,
			ERR_FUNC_ARG_TYPE, arguments[i]->lineNumber,
			"Type of argument " << i+1 << " in call to "
			"function " << function->name << " is not the "
			"same as the type of the function's parameter "
			"(" << argType->asString() << " value "
			"for " << paramType->asString() << " parameter.)");
		    return;
		}
	    }
	    else
	    {
		//
		// input parameter -- it must be possible to cast
		// the argument type to the parameter type
		//

		if (!paramType->canCastFrom (argType))
		{
		    MESSAGE_LE (lcontext, ERR_FUNC_ARG_TYPE,
			arguments[i]->lineNumber,
			"Cannot convert the type of argument " << i+1 << " "
			"in call to function " << function->name << " "
			"to the type of the function's parameter "
			"(" << argType->asString() << " value "
			"for " << paramType->asString() << " parameter.)");
		    return;
		}
	    }
	}
	else
	{
	    //
	    // We have no function call argument for parameter i.
	    // The parameter must have a default value.
	    //

	    if (!parameters[i].defaultValue)
	    {
		MESSAGE_LE (lcontext, ERR_FUNC_ARG_NUM,
		    function->lineNumber,
		    "Not enough arguments in call to "
		    "function " << function->name << ".");
		return;
	    }
	}
    }

    //
    // If we get here, then the call is valid.
    //

    type = functionType->returnType();
}
Exemplo n.º 15
0
DataTypePtr removeNullable(const DataTypePtr & type)
{
    if (type->isNullable())
        return static_cast<const DataTypeNullable &>(*type).getNestedType();
    return type;
}
Exemplo n.º 16
0
DataTypePtr makeNullable(const DataTypePtr & type)
{
    if (type->isNullable())
        return type;
    return std::make_shared<DataTypeNullable>(type);
}