Beispiel #1
0
        public Set(IXTable source, string outputColumnName, IXColumn column) : base(source)
        {
            _calculatedColumn = column;
            _columns          = new List <IXColumn>(source.Columns);

            // Determine whether we're replacing or adding a column
            if (source.Columns.TryGetIndexOfColumn(outputColumnName, out _computedColumnIndex))
            {
                _columns[_computedColumnIndex] = RenamedColumn.Build(_calculatedColumn, outputColumnName);
            }
            else
            {
                _columns.Add(RenamedColumn.Build(_calculatedColumn, outputColumnName));
                _computedColumnIndex = source.Columns.Count;
            }
        }
Beispiel #2
0
        public Join(IXTable source, string joinFromColumn, IXTable joinToSource, string joinToColumn, string joinSidePrefix)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _source       = source;
            _joinToSource = joinToSource;

            // Request the JoinFromColumn Getter
            IXColumn joinFrom = source.Columns.Find(joinFromColumn);

            _joinColumnType       = joinFrom.ColumnDetails.Type;
            _joinFromColumnGetter = joinFrom.CurrentGetter();

            // Request the JoinToColumn Reader (we'll need it cached)
            _joinToColumn = _joinToSource.Columns.Find(joinToColumn);
            Type joinToColumnType = _joinToColumn.ColumnDetails.Type;

            if (joinToColumnType != _joinColumnType)
            {
                throw new ArgumentException($"Join requires columns of matching types; join from {_joinColumnType.Name} to {joinToColumnType.Name} not supported.");
            }
            _joinToSeekGetter = _joinToColumn.SeekGetter();

            // Build a remapper for left side columns
            _sourceJoinedRowsFilter = new RowRemapper();

            // Build column wrappers
            _columns          = new IXColumn[source.Columns.Count + joinToSource.Columns.Count];
            _rightSideColumns = new SeekedColumn[joinToSource.Columns.Count];

            // Left Side columns are filtered to rows that joined (inner join)
            for (int i = 0; i < source.Columns.Count; ++i)
            {
                _columns[i] = new RemappedColumn(source.Columns[i], _sourceJoinedRowsFilter);
            }

            // Right side columns are seeked to the right side matching rows
            for (int i = 0; i < joinToSource.Columns.Count; ++i)
            {
                SeekedColumn column = new SeekedColumn(RenamedColumn.Build(joinToSource.Columns[i], joinSidePrefix + joinToSource.Columns[i].ColumnDetails.Name));
                _rightSideColumns[i] = column;
                _columns[i + source.Columns.Count] = column;
            }
        }
Beispiel #3
0
        public Rename(IXTable source, Dictionary <string, string> columnNameMappings) : base(source)
        {
            _mappedColumns = new List <IXColumn>();

            foreach (IXColumn column in _source.Columns)
            {
                IXColumn mapped = column;

                string newName;
                if (columnNameMappings.TryGetValue(column.ColumnDetails.Name, out newName))
                {
                    mapped = RenamedColumn.Build(column, newName);
                }

                _mappedColumns.Add(mapped);
            }
        }
Beispiel #4
0
        public IXColumn NextColumn(IXTable source, XDatabaseContext context, Type requiredType = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            IXColumn result = null;

            if (_scanner.Current.Type == TokenType.Value)
            {
                object value = String8.Convert(_scanner.Current.Value, new byte[String8.GetLength(_scanner.Current.Value)]);

                if (requiredType != null && requiredType != typeof(String8))
                {
                    value = TypeConverterFactory.ConvertSingle(value, requiredType);
                }

                result = new ConstantColumn(source, value, (requiredType == null ? typeof(String8) : requiredType), !_scanner.Current.IsWrapped);
                _scanner.Next();
            }
            else if (_scanner.Current.Type == TokenType.FunctionName)
            {
                result = NextFunction(source, context);
            }
            else if (_scanner.Current.Type == TokenType.ColumnName)
            {
                result = source.Columns.Find(NextColumnName(source, requiredType));
            }

            if (result == null || (requiredType != null && result.ColumnDetails.Type != requiredType))
            {
                Throw("Col|Func|Const", EscapedColumnList(source, requiredType).Concat(EscapedFunctionList(requiredType)));
            }

            if (_scanner.Current.Value.Equals("as", StringComparison.OrdinalIgnoreCase))
            {
                _scanner.Next();
                string columnName = NextOutputColumnName(source);
                result = RenamedColumn.Build(result, columnName);
            }

            return(result);
        }