示例#1
0
/*
 * walks through the column-definitions and if a column
 * has the to_copy-flag set, and it's name is in the
 * given list of column-names the to copy-flag is cleared
 * does not require an open cursor.
*/
rc_t col_defs_exclude_these_columns( col_defs* defs, const char * prefix, const char * column_names )
{
    rc_t rc = 0;
    const KNamelist *names;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    /* it is OK if we have not column-names to exclude */
    if ( column_names == NULL )
        return 0;
    if ( column_names[0] == 0 )
        return 0;

    rc = nlt_make_namelist_from_string( &names, column_names );
    DISP_RC( rc, "col_defs_parse_string:nlt_make_namelist_from_string() failed" );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        size_t prefix_len = 0;
        if ( prefix != 0 )
            prefix_len = string_size( prefix ) + 2;
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
            {
                if ( col->requested )
                {
                    if ( nlt_is_name_in_namelist( names, col->name ) )
                        col->requested = false;
                    else
                    {
                        if ( prefix != NULL )
                        {
                            size_t len1 = string_size ( col->name ) + prefix_len;
                            char * s = malloc( len1 );
                            if ( s != NULL )
                            {
                                size_t num_writ;
                                rc_t rc1 = string_printf ( s, len1, &num_writ, "%s:%s", prefix, col->name );
                                if ( rc1 == 0 )
                                {
                                    if ( nlt_is_name_in_namelist( names, s ) )
                                        col->requested = false;
                                }
                                free( s );
                            }
                        }
                    }
                }
            }
        }
        KNamelistRelease( names );
    }
    return rc;
}
示例#2
0
bool nlt_compare_namelists( const KNamelist *nl1, const KNamelist *nl2, uint32_t * found )
{
    bool res = false;
    if ( nl1 != NULL && nl2 != NULL )
    {
        uint32_t count_1;
        rc_t rc = KNamelistCount( nl1, &count_1 );
        if ( rc == 0 )
        {
            uint32_t count_2;
            rc = KNamelistCount( nl2, &count_2 );
            if ( rc == 0 && count_1 == count_2 )
            {
                uint32_t idx;
                uint32_t in_nl2 = 0;
                for ( idx = 0; idx < count_1 && rc == 0; ++idx )
                {
                    const char *s;
                    rc = KNamelistGet( nl1, idx, &s );
                    if ( rc == 0 && s != NULL && nlt_is_name_in_namelist( nl2, s ) )
                        in_nl2++;
                }
                res = ( rc == 0 && in_nl2 == count_1 );
                if ( found != NULL ) *found = in_nl2;
            }
        }
    }
    return res;
}
示例#3
0
rc_t nlt_remove_names_from_namelist( const KNamelist *source,
                                     const KNamelist **dest, const KNamelist *to_remove )
{
    rc_t rc = 0;
    uint32_t count;

    if ( source == NULL || dest == NULL || to_remove == NULL )
        return RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull );
    *dest = NULL;
    rc = KNamelistCount( source, &count );
    if ( rc == 0 && count > 0 )
    {
        VNamelist *cleaned;
        rc = VNamelistMake ( &cleaned, count );
        if ( rc == 0 )
        {
            uint32_t idx;
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *s;
                rc = KNamelistGet( source, idx, &s );
                if ( rc == 0 )
                {
                    if ( !nlt_is_name_in_namelist( to_remove, s ) )
                        rc = VNamelistAppend ( cleaned, s );
                }
                rc = VNamelistToConstNamelist ( cleaned, dest );
            }
        }
    }
    return rc;
}
示例#4
0
rc_t col_defs_mark_writable_columns( col_defs* defs, VTable *tab, bool show )
{
    KNamelist *writables;
    rc_t rc;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( tab == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = VTableListWritableColumns ( tab, &writables );
    if ( rc == 0 )
    {
        uint32_t idx, count = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < count; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                if ( col->requested )
                    if ( nlt_is_name_in_namelist( writables, col->name ) )
                    {
                        if ( show )
                            KOutMsg( "writable column: >%s<\n", col->name );
                        col->to_copy = true;
                    }
        }
        KNamelistRelease( writables );
    }
    return rc;
}
示例#5
0
rc_t col_defs_unmark_do_not_redact_columns(  col_defs* defs,
                    const char * do_not_redact_cols )
{
    const KNamelist *names;
    rc_t rc;
    
    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( do_not_redact_cols == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &names, do_not_redact_cols );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                if ( col->redactable )
                    if ( nlt_is_name_in_namelist( names, col->name ) )
                        col->redactable = false;
        }
        KNamelistRelease( names );
    }
    return rc;
}
示例#6
0
/*
 * walks through the column-names and marks every column thats
 * name is in "redactable_cols" as redactable
 * sets the redact-value to zero
 * if the default-type of the column is in the list of dna-types
 * (a hardcoded list) it sets the redact-value to 'N'
 * does not require an open cursor. 
*/
rc_t col_defs_detect_redactable_cols_by_name( col_defs* defs,
                                const char * redactable_cols )
{
    const KNamelist *r_columns;
    rc_t rc;
    
    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( defs == NULL || redactable_cols == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &r_columns, redactable_cols );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len && rc == 0; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                if ( !(col->redactable) )
                    col->redactable = nlt_is_name_in_namelist( r_columns, col->name );
        }
        KNamelistRelease( r_columns );
    }
    return rc;
}
示例#7
0
rc_t nlt_build_intersect( const KNamelist *nl1, const KNamelist *nl2, const KNamelist ** dst )
{
    VNamelist *v_names;
    rc_t rc = VNamelistMake ( &v_names, 5 );
	if ( rc == 0 )
	{
		/* loop through nl1: if a entry is found in nl2 -> add it to dst */
		uint32_t count;
		rc = KNamelistCount( nl1, &count );
		if ( rc == 0 )
		{
            uint32_t idx;
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *s;
                rc = KNamelistGet( nl1, idx, &s );
				if ( rc == 0 && s != NULL )
				{
					if ( nlt_is_name_in_namelist( nl2, s ) )
						rc = VNamelistAppend ( v_names, s );
				}
			}
		}
		if ( rc == 0 )
			rc = VNamelistToConstNamelist ( v_names, dst );
        VNamelistRelease( v_names );

	}
	return rc;	
}
示例#8
0
static rc_t matcher_exclude_columns( matcher* self, const char * columns )
{
    const KNamelist *list;
    uint32_t len, idx;
    rc_t rc;

    if ( columns == NULL ) return 0;
    rc = nlt_make_namelist_from_string( &list, columns );
    len = VectorLength( &(self->mcols) );
    for ( idx = 0;  idx < len; ++idx )
    {
        p_mcol col = (p_mcol) VectorGet ( &(self->mcols), idx );
        if ( col != NULL )
            col->excluded = nlt_is_name_in_namelist( list, col->name );
    }
    KNamelistRelease( list );
    return rc;
}
示例#9
0
bool nlt_namelist_is_sub_set_in_full_set( const KNamelist * sub_set, const KNamelist * full_set )
{
    bool res = false;
    uint32_t count;
    rc_t rc = KNamelistCount( sub_set, &count );
    if ( rc == 0 )
    {
        uint32_t idx;
        uint32_t found = 0;
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *s;
            rc = KNamelistGet( sub_set, idx, &s );
            if ( rc == 0 && s != NULL && nlt_is_name_in_namelist( full_set, s ) )
                found++;
        }
        res = ( rc == 0 && count == found );
    }
    return res;
}
示例#10
0
rc_t col_defs_mark_requested_columns( col_defs* defs, const char * columns )
{
    const KNamelist *requested;
    rc_t rc;
    uint32_t idx, len;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );

    if ( columns == NULL )
    {
        /* no specific columns are provided --> mark all of them */
        len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                col->requested = true;
        }
        rc = 0;
    }
    else
    {
        /* specific columns are provided --> mark all of these */
        rc = nlt_make_namelist_from_string( &requested, columns );
        DISP_RC( rc, "col_defs_mark_requested_columns:nlt_make_namelist_from_string() failed" );
        if ( rc == 0 )
        {
            uint32_t idx, len = VectorLength( &(defs->cols) );
            for ( idx = 0;  idx < len; ++idx )
            {
                p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
                if ( col != NULL )
                    col->requested = nlt_is_name_in_namelist( requested, col->name );
            }
            KNamelistRelease( requested );
        }
    }
    return rc;
}
示例#11
0
static rc_t copy_metadata_root ( const KMDataNode *src_root, KMDataNode *dst_root,
                                 const char * excluded_nodes,
                                 const bool show_meta )
{
    KNamelist *names;
    const KNamelist *excluded_names = NULL;
    uint32_t i, count;

    rc_t rc = KMDataNodeListChild ( src_root, & names );
    DISP_RC( rc, "copy_metadata_root:KMDataNodeListChild() failed" );
    if ( rc != 0 ) return rc;
    
    if ( excluded_nodes != NULL )
    {
        rc = nlt_make_namelist_from_string( &excluded_names, excluded_nodes );
        DISP_RC( rc, "copy_metadata_root:nlt_make_namelist_from_string() failed" );
        if ( rc != 0 ) return rc;
    }

    rc = KNamelistCount ( names, & count );
    for ( i = 0; rc == 0 && i < count; ++ i )
    {
        const char *node_path;
        rc = KNamelistGet ( names, i, & node_path );
        DISP_RC( rc, "copy_metadata_root:KNamelistGet() failed" );
        if ( rc == 0 )
        {
            bool is_excluded = false;
            if ( excluded_names != NULL )
                is_excluded = nlt_is_name_in_namelist( excluded_names, node_path );
            if ( !is_excluded )
                rc = copy_metadata_child ( src_root, dst_root, node_path, show_meta );
        }
    }

    if ( excluded_names != NULL )
        KNamelistRelease( excluded_names );
    KNamelistRelease ( names );
    return rc;
}