Esempio n. 1
0
        /**
         * Returns selected columns as a bool array with true value set for specified column names.
         * The result will contain number of elements equal to flattened number of columns.
         * For example:
         * selectedColumns - a,b,c
         * allColumns - a,b,c,d
         * If column c is a complex type, say list<string> and other types are primitives then result will
         * be [false, true, true, true, true, true, false]
         * Index 0 is the root element of the struct which is set to false by default, index 1,2
         * corresponds to columns a and b. Index 3,4 correspond to column c which is list<string> and
         * index 5 correspond to column d. After flattening list<string> gets 2 columns.
         *
         * @param selectedColumns - comma separated list of selected column names
         * @param schema       - object schema
         * @return - bool array with true value set for the specified column names
         */
        public static bool[] includeColumns(string selectedColumns, TypeDescription schema)
        {
            int numFlattenedCols = schema.getMaximumId();

            bool[] results = new bool[numFlattenedCols + 1];
            if ("*".Equals(selectedColumns))
            {
                for (int i = 0; i < results.Length; i++)
                {
                    results[i] = true;
                }
                return(results);
            }
            if (selectedColumns != null &&
                schema.getCategory() == Category.STRUCT)
            {
                IList <string>          fieldNames = schema.getFieldNames();
                IList <TypeDescription> fields     = schema.getChildren();
                foreach (string column in selectedColumns.Split((',')))
                {
                    TypeDescription col = findColumn(column, fieldNames, fields);
                    if (col != null)
                    {
                        for (int i = col.getId(); i <= col.getMaximumId(); ++i)
                        {
                            results[i] = true;
                        }
                    }
                }
            }
            return(results);
        }