public void InitJoining() { // Initialize this field for joining data to it! FieldsImpacted = new HqlFieldGroup(); _onJoin = new HqlWhere(HqlWhere.NAME_ONJOIN); Lines = new List <HqlValues>(); }
public HqlValuesComparer(HqlDataSource prior, HqlWhere onJoin, HqlWhere where) //, HqlWith settings) { _prior = prior; _onJoin = onJoin; _where = where; //_settings = settings; _orderOfSortFields = new ArrayList(); _mode = HqlCompareMode.SORT_MODE; _onJoin.CreateSortFields(this); _where.CreateSortFields(this); _currentPrior = -1; _joinMethod = HqlJoinMethod.SORT_COMPARE; }
public void Compile() { try { _select = new HqlSelect(_settings); _from = new HqlFrom(); _where = new HqlWhere(HqlWhere.NAME_WHERE); _groupby = new HqlGroupBy(); _having = new HqlHaving(_select); _orderby = new HqlOrderBy(); HqlTokenProcessor processor = new HqlTokenProcessor(_sql, _settings, _references); Compile_Inner(processor); PostCompile(processor); } catch { throw; } }
//public HqlValues MergeValues(HqlValues priorvalues, HqlValues thisvalues, ref HqlFieldGroup combinedFields) //{ // if (combinedFields == null) // combinedFields = new HqlFieldGroup(priorvalues.FieldsImpacted, thisvalues.FieldsImpacted); // return new HqlValues(combinedFields, priorvalues, thisvalues); //} public bool ReadThroughUsingJoin(HqlDataSource prior, HqlWhere onJoin, HqlWhere where, bool selectRecord) { // TODO // - need to sort the prior how I'm going to join these. // - read through current and join them and save to new object // - clear all the saved data from the prior object //HqlFieldGroup combinedFieldsImpacted = null; //HqlValuesComparer comparer = prior.comparer; // TODO, sort the prior //bool sortedPrior = false; for (; ;) { if (selectRecord && Lines.Count > 0) { _resultValues = Lines[0]; Lines.RemoveAt(0); if (where.Evaluate(_resultValues)) { return(true); } continue; } if (EndOfStream) { if (!_completedJoin) { _completedJoin = true; if (prior != null && (prior.JoinType == HqlKeyword.LEFT_OUTER || prior.JoinType == HqlKeyword.FULL_OUTER)) { prior.Comparer.JoinMethod = HqlJoinMethod.RETURN_ALL; prior.Comparer.Reset(); prior.comparer.SetValues(BlankValues); for (; prior.Comparer.MoveNext();) { prior.Comparer.Current.IncreaseUsedCount(); HqlValues combinedvalues = prior.Comparer.CombinedValues; SaveRowValue(combinedvalues); } continue; } } _resultValues = null; return(false); } //string fromline = ReadLine(); //if (fromline.Equals(String.Empty) && EndOfStream) // continue; //HqlLine line = new HqlLine(fromline, settings, RowNum) HqlLine line = ReadLine(); if (line.IsBlank && EndOfStream) { continue; } #if DEBUG if (line.Line.StartsWith("1503|706")) { int stop = 0; } #endif // get the current line of data HqlValues thisvalues = new HqlValues(FieldsImpacted, line); // does this match the where statement? if (JoinType == HqlKeyword.LEFT_OUTER || JoinType == HqlKeyword.FULL_OUTER) { // pass through, don't evaluate the ON command because I want this regardless } else if (prior != null && (prior.JoinType == HqlKeyword.FULL_OUTER || prior.JoinType == HqlKeyword.RIGHT_OUTER)) { // pass through } else if (!onJoin.EvaluateJoin(thisvalues, true)) // || !where.EvaluateJoin(thisvalues)) { // didn't pass through, so continue continue; } // This is here for the first "join" // I need to save all the records. if (prior == null) { SaveRowValue(thisvalues); continue; } // now time to join the data! bool savedThisRecord = false; // do preprocessing if this is to be searched through sorting if (prior.Comparer == null) { if (prior.Lines.Count == 0) { throw new Exception("Data integrity issue. Didn't find anything to join with on prior! TODO, this can be valid, need to fix!!"); } HqlValues priorvalues = prior.Lines[0]; // guaranteed to be there prior.Comparer = new HqlValuesComparer(prior, onJoin, where); //, settings); prior.Comparer.CombinedFieldsImpacted = new HqlFieldGroup(priorvalues.FieldsImpacted, thisvalues.FieldsImpacted); if (prior.Comparer.CountOfJoinFields == 0) { prior.Comparer.JoinMethod = HqlJoinMethod.LINEAR_COMPARE; } Console.Error.WriteLine(String.Format("Using joining of {0} between ({1}) {2} and ({3}) {4}", prior.Comparer.JoinMethod.ToString(), prior.TableReference, prior.SourceName, this.TableReference, this.SourceName) ); if (prior.Comparer.JoinMethod == HqlJoinMethod.SORT_COMPARE) { prior.Comparer.SortPrior(); } } prior.Comparer.SetValues(thisvalues); prior.Comparer.Reset(); for (; prior.Comparer.MoveNext();) { prior.Comparer.Current.IncreaseUsedCount(); HqlValues combinedvalues = prior.Comparer.CombinedValues; SaveRowValue(combinedvalues); savedThisRecord = true; } if (!savedThisRecord && (prior.JoinType == HqlKeyword.RIGHT_OUTER || prior.JoinType == HqlKeyword.FULL_OUTER)) { HqlValues combinedvalues = new HqlValues(prior.Comparer.CombinedFieldsImpacted, prior.BlankValues, thisvalues); SaveRowValue(combinedvalues); } } }