예제 #1
0
        private bool TryBuildNextCell(Field f, Dictionary <string, LazyColumnEnumerator> pathToColumn, out object cell)
        {
            switch (f.SchemaType)
            {
            case SchemaType.Data:
                LazyColumnEnumerator dce = pathToColumn[f.Path];
                //MoveNext returns either an element or a list-like structure for columns that are repeated
                if (!dce.MoveNext())
                {
                    cell = null;
                    return(false);
                }
                cell = dce.Current;

                break;

            case SchemaType.Map:
                bool mcok = TryBuildMapCell((MapField)f, pathToColumn, out IReadOnlyList <Row> mapRow);
                cell = mapRow;
                return(mcok);

            case SchemaType.Struct:
                bool scok = TryBuildStructCell((StructField)f, pathToColumn, out Row scRow);
                cell = scRow;
                return(scok);

            case SchemaType.List:
                return(TryBuildListCell((ListField)f, pathToColumn, out cell));

            default:
                throw OtherExtensions.NotImplemented(f.SchemaType.ToString());
            }

            return(true);
        }
예제 #2
0
        private bool TryBuildMapCell(MapField mf, Dictionary <string, LazyColumnEnumerator> pathToColumn, out IReadOnlyList <Row> rows)
        {
            //"cut into" the keys and values collection
            LazyColumnEnumerator keysCollection   = pathToColumn[mf.Key.Path];
            LazyColumnEnumerator valuesCollection = pathToColumn[mf.Value.Path];

            if (keysCollection.MoveNext() && valuesCollection.MoveNext())
            {
                var ptc = new Dictionary <string, LazyColumnEnumerator>
                {
                    [mf.Key.Path]   = (LazyColumnEnumerator)keysCollection.Current,
                    [mf.Value.Path] = (LazyColumnEnumerator)valuesCollection.Current
                };

                rows = BuildRows(new[] { mf.Key, mf.Value }, ptc);
                return(true);
            }

            rows = null;
            return(false);
        }
예제 #3
0
        public IReadOnlyCollection <Row> Convert()
        {
            var pathToColumn = new Dictionary <string, LazyColumnEnumerator>();

            foreach (DataColumn column in _columns)
            {
                var en = new LazyColumnEnumerator(column);
                en.Reset();

                pathToColumn[column.Field.Path] = en;
            }

            var result = new List <Row>();

            ColumnsToRows(_schema.Fields, pathToColumn, result, _totalRowRount);

            foreach (Row row in result)
            {
                row.Schema = _schema.Fields.ToArray();
            }

            return(result);
        }