Пример #1
0
//==============================================================
//this is the function that reads in the table
//==============================================================
int readFData(FILE *fp, fData *t, const fDataType *types) {
    char **currentRow;
    char *rowPtr;
    int rowCount = 0;
    int i;
    int errFlag = 0;//not used, but possibly for future usage. set when data types disagree

    //allocate the datatypes table, and set the default values
    t->types = (fDataType *) malloc(sizeof(fDataType) * t->numCols);
    for (i = 0; i < t->numCols; i++) {
        t->types[i].type = INT;
        t->types[i].sigDigits = 0;
        t->types[i].inSigDigits = 0;
    }

    //allocate the first row of data
    t->data = (char ***) malloc((sizeof(char **)));

    while (!EOFDETECTED) {
        //read in a row
        if ((rowPtr = getRow(fp)) == NULL) break; //this is not really an error
        //parse the row
        currentRow = readRow(rowPtr, t->numCols);
        if (types != NULL)//check to see if the dataTypes in TYPES are OK with the data read.
        {
            if (!verifyRow(currentRow, types, t->numCols)) {
                fprintf(stderr, "On row %d\n", rowCount);
                errFlag = 1;
            }
        }
        if (EOFDETECTED) break;
        if (!currentRow) {
            fprintf(stderr, "Flib::readRawData: I cant read line #%d\n", rowCount);
            t->data = NULL;
            return 1;;
        }

        //make space for another row
        t->data = (char ***) realloc(t->data, (sizeof(char **) * (rowCount + 1)));
        //set the values for the row, and increment rowCount
        t->data[rowCount++] = currentRow;

        getDataTypes(t->numCols, t->types, currentRow);
        free(rowPtr);
    }

    t->numRows = rowCount;
    return errFlag;
}
Пример #2
0
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) override
    {
        /// Second argument must be ColumnSet.
        ColumnPtr column_set_ptr = block.getByPosition(arguments[1]).column;
        const ColumnSet * column_set = typeid_cast<const ColumnSet *>(&*column_set_ptr);
        if (!column_set)
            throw Exception("Second argument for function '" + getName() + "' must be Set; found " + column_set_ptr->getName(),
                ErrorCodes::ILLEGAL_COLUMN);

        Block block_of_key_columns;

        /// First argument may be tuple or single column.
        const ColumnWithTypeAndName & left_arg = block.getByPosition(arguments[0]);
        const ColumnTuple * tuple = typeid_cast<const ColumnTuple *>(left_arg.column.get());
        const ColumnConst * const_tuple = checkAndGetColumnConst<ColumnTuple>(left_arg.column.get());
        const DataTypeTuple * type_tuple = typeid_cast<const DataTypeTuple *>(left_arg.type.get());

        ColumnPtr materialized_tuple;
        if (const_tuple)
        {
            materialized_tuple = const_tuple->convertToFullColumn();
            tuple = typeid_cast<const ColumnTuple *>(materialized_tuple.get());
        }

        auto set = column_set->getData();
        auto set_types = set->getDataTypes();
        if (tuple && (set_types.size() != 1 || !set_types[0]->equals(*type_tuple)))
        {
            const Columns & tuple_columns = tuple->getColumns();
            const DataTypes & tuple_types = type_tuple->getElements();
            size_t tuple_size = tuple_columns.size();
            for (size_t i = 0; i < tuple_size; ++i)
                block_of_key_columns.insert({ tuple_columns[i], tuple_types[i], "" });
        }
        else
            block_of_key_columns.insert(left_arg);

        block.getByPosition(result).column = set->execute(block_of_key_columns, negative);
    }