Beispiel #1
0
static
rc_t VProdResolveColExpr ( const VProdResolve *self, VProduction **out,
    VFormatdecl *fd, const SSymExpr *x, bool casting )
{
    rc_t rc;
    const SNameOverload *sname;
    const KSymbol *sym = x -> _sym;

    BSTree ordered;
    uint32_t i, count;
    SColumnBestFit buff [ 16 ], * nodes = buff;

    /* fail if "fd" has a format */
    if ( fd -> fmt != 0 )
    {
        PLOGMSG ( klogWarn, ( klogWarn, "illegal cast of column '$(name)'"
                   , "name=%.*s"
                   , ( int ) sym -> name . size
                   , sym -> name . addr ));
        return 0;
    }

    /* allocate nodes for indexing columns */
    sname = sym -> u . obj;
    count = VectorLength ( & sname -> items );
    if ( count > sizeof buff / sizeof buff [ 0 ] )
    {
        nodes = malloc ( sizeof * nodes * count );
        if ( nodes == NULL )
            return RC ( rcVDB, rcProduction, rcResolving, rcMemory, rcExhausted );
    }

    /* insert columns into ordered tree */
    BSTreeInit ( & ordered );
    for ( i = VectorStart ( & sname -> items ), count += i; i < count; ++ i )
    {
        /* get SColumn */
        nodes [ i ] . scol = ( const void* ) VectorGet ( & sname -> items, i );

        /* perform type cast and measure distance */
        if ( casting ?
             VTypedeclCommonAncestor ( & nodes [ i ] . scol -> td, self -> schema,
                 & fd -> td, & nodes [ i ] . td, & nodes [ i ] . distance ) :
             VTypedeclToTypedecl ( & nodes [ i ] . scol -> td, self -> schema,
                 & fd -> td, & nodes [ i ] . td, & nodes [ i ] . distance ) )
        {
            BSTreeInsert ( & ordered, & nodes [ i ] . n, order_column );
        }
    }

    /* try to resolve each in order */
    rc = VProdResolveBestColumn ( self, out, & ordered, x -> alt );

    if ( nodes != buff )
        free ( nodes );

    return rc;
}
Beispiel #2
0
static void CC matcher_measure_dist_cb( void * item, void * data )
{
    p_mpair pair = (p_mpair)item;
    const VSchema *schema = (const VSchema *)data;
    if ( pair != NULL && schema != NULL )
    {
        bool compatible = VTypedeclCommonAncestor ( &(pair->src->type_decl),
                schema, &(pair->dst->type_decl), NULL, &(pair->distance) );
        pair->compatible = ( compatible ? 0 : 1 );
    }
}