Skip to content

Commit

Permalink
#582 some view column attributes are not propagated in expansion
Browse files Browse the repository at this point in the history
When doing a .*, many view column attributes (e.g., coalesce, aggregate,
expression...) are not propagated properly.

Need to test for #525 as this could be the same fix.
  • Loading branch information
ldhasson committed Jun 8, 2021
1 parent 044d334 commit a98c1cf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/tilda/parsing/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ private static boolean loadDependencies(Schema S, Map<String, Schema> Dependenci
for (String d : S._Dependencies)
{
Schema D = SchemaCache.get(d);
boolean cache = false;
if (D == null)
{
LOG.info("Loading dependency schema from '" + d + "'.");
Expand All @@ -208,12 +209,14 @@ private static boolean loadDependencies(Schema S, Map<String, Schema> Dependenci
}
else
{
LOG.info("Tilda schema from '" + d + "' has already been loaded previously and has been fetched from the cache.");
LOG.info(" Tilda schema from '" + d + "' was found in the cache.");
cache = true;
}
Schema Pre = Dependencies.get(D.getFullName());
if (Pre != null)
{
LOG.info(" Tilda dependency schema '" + Pre.getFullName() + "' has been loaded already");
if (cache == false)
LOG.info(" Tilda dependency schema '" + Pre.getFullName() + "' has been validated already");
S._DependencySchemas.add(Pre);
}
else
Expand Down
14 changes: 0 additions & 14 deletions src/tilda/parsing/parts/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,6 @@ else if (_FST != FrameworkSourcedType.VIEW && _FST != FrameworkSourcedType.REALI
}

Set<String> Names = new HashSet<String>();
/*
* for (int i = 0; i < _Migrations.length; ++i)
* {
* Migration M = _Migrations[i];
* if (M != null)
* if (M.Validate(PS, this, i) == true)
* {
* for (String col : M._ColumnNames)
* if (Names.add(col) == false)
* PS.AddError("Object '" + getFullName() + "' has declared migration #" + i + " with a column '" + col + "' which has already been specified in another migration!");
* }
* }
*/


_HasUniqueIndex = false;
Set<String> Signatures = new HashSet<String>();
Expand Down
4 changes: 2 additions & 2 deletions src/tilda/parsing/parts/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ public ViewColumn getViewColumn(String viewName, String columnName)
public boolean Validate(ParserSession PS)
throws Exception
{
LOG.info("Validating Tilda Schema '" + getFullName() + "'.");
if (_Validated != null)
{
LOG.info(" --> The Schema '" + getFullName() + "' has already been validated.");
LOG.info("Tilda Schema '" + getFullName() + "' has already been validated.");
return _Validated;
}
LOG.info("Validating Tilda Schema '" + getFullName() + "'.");

int Errs = PS.getErrorCount();
int i = -1;
Expand Down
46 changes: 41 additions & 5 deletions src/tilda/parsing/parts/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,15 @@ else if (ObjectNames.size() == 1 && VC._Join != null)
PS.AddError("The View '" + _Name + "' is defining a 'pivotColumns' element which is deprecated. Please use the new 'pivots' constructs instead.");
if (TextUtil.isNullOrEmpty(_CountStarDeprecated) == false)
PS.AddError("View '" + getFullName() + "' is defining a 'countStar' element which is deprecated. Please use a standard column definition with an aggregate of 'COUNT'.");

// gotta construct a shadow Object for code-gen.
// LOG.debug("View " + _Name + ": " + TextUtil.print(getColumnNames()));
Object O = MakeObjectProxy(PS);
// LOG.debug("Object " + O._Name + ": " + TextUtil.print(O.getColumnNames()));

// LOG.debug("VIEW - "+this.getFullName()+": "+TextUtil.print(this.getColumnNames()));
// LOG.debug("OBJECT - "+O.getFullName()+": "+TextUtil.print(O.getColumnNames()));

if (_Realize != null)
_Realize.Validate(PS, this, new ViewRealizedWrapper(O, this));

Expand All @@ -388,6 +391,7 @@ else if (ObjectNames.size() == 1 && VC._Join != null)
private boolean HandleStarExpansion(ParserSession PS, int i, ViewColumn VC)
{
_ViewColumns.remove(i);

int lastDot = VC._SameAs.lastIndexOf('.');
String startingWith = VC._SameAs.substring(lastDot + 1, VC._SameAs.length() - 1);
VC._SameAs = VC._SameAs.substring(0, lastDot);
Expand Down Expand Up @@ -862,8 +866,7 @@ private void CopyDependentObjectFields(int i, ViewColumn VC, String Prefix, Obje
for (Column col : O._Columns)
{
if (col._FCT == FrameworkColumnType.TZ
|| col._FCT != FrameworkColumnType.NONE && col._FCT != FrameworkColumnType.TS && col._FCT.isOCC() == false)
// if (col._FrameworkManaged == true)
|| col._FCT != FrameworkColumnType.NONE && col._FCT != FrameworkColumnType.FORMULA && col._FCT != FrameworkColumnType.FORMULA_DT && col._FCT != FrameworkColumnType.TS && col._FCT.isOCC() == false)
continue;
if (TextUtil.findStarElement(VC._Exclude, col._Name, true, 0) != -1)
continue;
Expand All @@ -876,6 +879,7 @@ private void CopyDependentObjectFields(int i, ViewColumn VC, String Prefix, Obje
NewVC._As = VC._As;
NewVC._Name = Prefix + col.getName();
NewVC._FCT = col._FCT;
copyAdvancedViewColumnFields(VC, NewVC);
_ViewColumns.add(i + j, NewVC);
++j;
}
Expand All @@ -885,10 +889,12 @@ private void CopyDependentObjectFields(int i, ViewColumn VC, String Prefix, Obje
private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V, String startingWith)
{
int j = 0;
// LOG.debug("VIEWCOLUMN * - "+VC._SameAs+" -> "+ V.getFullName()+": "+TextUtil.print(V.getColumnNames()));
for (ViewColumn col : V._ViewColumns)
{
// LOG.debug(" - Looking at "+col.getFullName()+"; startingWith: "+startingWith+"; _FCT: "+col._FCT+";");
if (col._FCT == FrameworkColumnType.TZ
|| col._FCT != FrameworkColumnType.NONE && col._FCT != FrameworkColumnType.TS && col._FCT.isOCC() == false)
|| col._FCT != FrameworkColumnType.NONE && col._FCT != FrameworkColumnType.FORMULA && col._FCT != FrameworkColumnType.FORMULA_DT && col._FCT != FrameworkColumnType.TS && col._FCT.isOCC() == false)
continue;
if (TextUtil.findStarElement(VC._Exclude, col._Name, true, 0) != -1)
continue;
Expand All @@ -912,6 +918,7 @@ private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V
NewVC._Scale = col._Scale;
NewVC._Precision = col._Precision;
}
copyAdvancedViewColumnFields(VC, NewVC);

if (TextUtil.findStarElement(VC._Block, col._Name, true, 0) != -1)
NewVC._FormulaOnly = true;
Expand All @@ -938,6 +945,7 @@ private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V
NewVC._SameAs = V.getFullName() + "." + SrcColName;
NewVC._As = VC._As;
NewVC._Name = Prefix + SrcColName;
copyAdvancedViewColumnFields(VC, NewVC);
_ViewColumns.add(i + j, NewVC);
_PadderColumnNames.track(NewVC.getName());
++j;
Expand All @@ -957,6 +965,7 @@ private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V
NewVC._SameAs = V.getFullName() + "." + SrcColName;
NewVC._As = VC._As;
NewVC._Name = Prefix + SrcColName;
copyAdvancedViewColumnFields(VC, NewVC);
_ViewColumns.add(i + j, NewVC);
_PadderColumnNames.track(NewVC.getName());
++j;
Expand All @@ -973,7 +982,9 @@ private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V
NewVC._SameAs = V.getFullName() + "." + F._Name;
NewVC._Name = Prefix + F._Name;
NewVC._As = VC._As;
NewVC._FCT = VC._FCT;
// When copying a formula from a prior view, the column type should become NONE as it no longer has the properties of a formula.
NewVC._FCT = FrameworkColumnType.NONE;//VC._FCT;
copyAdvancedViewColumnFields(VC, NewVC);
if (TextUtil.findStarElement(VC._Block, F._Name, true, 0) != -1)
NewVC._FormulaOnly = true;
_ViewColumns.add(i + j, NewVC);
Expand All @@ -982,6 +993,31 @@ private void CopyDependentViewFields(int i, ViewColumn VC, String Prefix, View V
}
}

/**
* Copies field values from VC to NewVC. Handles _AggregateStr, _FormulaOnly, _JoinOnly, _Coalesce, _Distinct
* _OrderBy, _Filter, _Expression, _TypeStr, _Size, _Scale, _Precision.
* @param VC
* @param NewVC
*/
protected void copyAdvancedViewColumnFields(ViewColumn VC, ViewColumn NewVC)
{
NewVC._AggregateStr = VC._AggregateStr;
NewVC._FormulaOnly = VC._FormulaOnly;
NewVC._JoinOnly = VC._JoinOnly;
NewVC._Coalesce = VC._Coalesce;
NewVC._Distinct = VC._Distinct;
NewVC._OrderBy = VC._OrderBy;
NewVC._Filter = VC._Filter;
if (TextUtil.isNullOrEmpty(VC._Expression) == false)
{
NewVC._Expression = VC._Expression;
NewVC._TypeStr = VC._TypeStr;
NewVC._Size = VC._Size;
NewVC._Scale = VC._Scale;
NewVC._Precision = VC._Precision;
}
}

/*
* private Column getSameAsColumn(String ObjectFullName, String ColName)
* {
Expand Down
2 changes: 1 addition & 1 deletion src/tilda/parsing/parts/ViewColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static Column ValidateSameAs(ParserSession PS, String ColFullName, String
{
// If the view is realized, it should not have direct dependencies on other realized views since the system can handle automatically these dependencies
if (ParentView._Realize != null && (Col._ParentObject._TildaType == TildaType.REALIZED_VIEW || Col._ParentObject._FST == FrameworkSourcedType.REALIZED))
PS.AddError("View column '" + ColFullName + "' is declaring sameas '" + SameAs + "' resolving to a realized view '" + R.getFullObjectName() + "', which is not allowed. Refills automatically handle this.");
PS.AddError("View column '" + ColFullName + "' is declaring sameas '" + SameAs + "' resolving to a realized view '" + R.getFullObjectName() + "', which is not allowed. Refills automatically handle cases when realized views reference other realized views. If you want to break the chain, create an intermediate unrealized view.");
else
return Col;
}
Expand Down
7 changes: 5 additions & 2 deletions src/tilda/parsing/parts/ViewRealize.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean Validate(ParserSession PS, View ParentView, ViewRealizedWrapper P
O._SourceView = ParentView;
O._Name = ParentView.getRealizedTableName(false);
O._ShortAlias = ParentView._ShortAlias;

Schema targetSchema = null;
if (TextUtil.isNullOrEmpty(_TargetSchema) == false)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ public boolean Validate(ParserSession PS, View ParentView, ViewRealizedWrapper P
}

boolean OCC = false;
// LOG.debug(ParentRealized._O.getFullName()+": "+TextUtil.print(ParentRealized._O.getColumnNames()));
// LOG.debug(ParentRealized._O.getFullName()+": "+TextUtil.print(ParentRealized._O.getColumnNames()));
for (Column C : ParentRealized._O._Columns)
{
if (TextUtil.findStarElement(_Exclude_DEPRECATED, C._Name, true, 0) == -1)
Expand Down Expand Up @@ -190,7 +190,10 @@ public boolean Validate(ParserSession PS, View ParentView, ViewRealizedWrapper P
// newCol._SameAsObj = C._SameAsObj;
O._Columns.add(newCol);
}
// else
// LOG.debug("Excluding "+C._Name);
}
// LOG.debug(O.getFullName()+": "+TextUtil.print(O.getColumnNames()));

// We can't just copy the OCC status of the view because we don't know which columns are actually used.
O._OCC = O.getColumn("created") != null && O.getColumn("lastUpdated") != null && O.getColumn("deleted") != null;
Expand Down

0 comments on commit a98c1cf

Please sign in to comment.