// a column declaration only creates or adds to the column meta data. it does not create the actual column. public void BuildOrUpdateDeclaration(ViewTable.Builder.BuildingData buildingData, ViewTable vTable, ref MetaColumn metaColumn, Operation.ExpressionParsingContext expressionParsingContext, Type aOverrideType = null) { Type finalType = aOverrideType != null ? aOverrideType : (value == null ? null : value.type ); //Build meta data var mergeAlgo = BuildOrGetMergeAlgo(null, finalType, metaColumn); BuildOrUpdateMetaColumn(buildingData, ref metaColumn, finalType, mergeAlgo); if (metaColumn != null && metaColumn.Type.scriptingType == null && finalType == null && !buildingData.FallbackColumnType.ContainsKey(metaColumn)) { Operation.Expression.ParseIdentifierOption parseOpt = new Operation.Expression.ParseIdentifierOption(buildingData.Schema, vTable, true, false, null, expressionParsingContext); var fallbackType = Operation.Expression.ResolveTypeOf(value, parseOpt); if (fallbackType != null) { buildingData.FallbackColumnType.Add(metaColumn, fallbackType); } } }
//A column under a <Node> (or <View>) element is either a declaration (build meta data only) or defines an entry in the parent's ViewColumnNode public void BuildNodeValue(ViewTable.Builder.BuildingData buildingData, ViewTable vTable, ViewTable.Builder.Node node, long row, ViewTable parentViewTable, Operation.ExpressionParsingContext expressionParsingContext, ref Database.MetaColumn metaColum) { BuildOrUpdateDeclaration(buildingData, vTable, ref metaColum, expressionParsingContext); //If the parent's node data type is Node if (node.parent != null && node.parent.data.type == ViewTable.Builder.Node.Data.DataType.Node) { // this column is an entry in the parent's column var option = new Operation.Expression.ParseIdentifierOption(buildingData.Schema, parentViewTable, true, true, metaColum != null ? metaColum.Type.scriptingType : null, expressionParsingContext); option.formatError = (string s, Operation.Expression.ParseIdentifierOption opt) => { return(FormatErrorContextInfo(buildingData.Schema, parentViewTable) + " : " + s); }; Operation.Expression expression = Operation.Expression.ParseIdentifier(value, option); //if the meta column does not have a type defined yet, define it as the expression's type. if (metaColum.Type.scriptingType == null) { DataMatchMethod matchMethod = expression.type == typeof(string) ? DataMatchMethod.AsString : DataMatchMethod.AsNumber; metaColum.Type = new MetaType() { scriptingType = expression.type, comparisonMethod = matchMethod }; } ViewColumnNode.IViewColumnNode column = BuildOrGetColumnNode(parentViewTable, metaColum, name, expressionParsingContext); column.SetEntry(row, expression, m_MetaLink); } }
private MetaColumn BuildOrUpdateMetaColumn(ViewTable.Builder.BuildingData buildingData, ref MetaColumn metaColumn, Type columnValueType, Operation.Grouping.IMergeAlgorithm mergeAlgo) { if (metaColumn == null) { metaColumn = new MetaColumn(name, name, columnValueType, isPrimaryKey, groupAlgo, mergeAlgo, FormatName, displayDefaultWidth); buildingData.MetaTable.AddColumn(metaColumn); } else { if (metaColumn.Type == null) { metaColumn.Type = columnValueType; } else if (columnValueType != null && metaColumn.Type != columnValueType) { Debug.LogError("Cannot redefine column type as '" + columnValueType + "'. Was already defined as '" + metaColumn.Type + "'"); } if (!String.IsNullOrEmpty(FormatName)) { if (String.IsNullOrEmpty(metaColumn.FormatName) || metaColumn.FormatName == FormatName) { metaColumn.FormatName = FormatName; } else { Debug.LogWarning("Format already defined as '" + metaColumn.FormatName + "'. Trying to redefined it as '" + FormatName + "'"); } } } return(metaColumn); }
// Set a Node value to the merged result of it's sub entries public static void BuildNodeValueDefault(ViewTable.Builder.BuildingData buildingData, ViewTable.Builder.Node node, long row, ViewTable parentViewTable, Operation.ExpressionParsingContext expressionParsingContext, Database.MetaColumn metaColumn) { //set the entry for merge column if (metaColumn.DefaultMergeAlgorithm != null && metaColumn.Type.scriptingType != null) { ViewColumnNode.IViewColumnNode column = BuildOrGetColumnNode(parentViewTable, metaColumn, metaColumn.Name, expressionParsingContext); Operation.Expression expression = Operation.ColumnCreator.CreateTypedExpressionColumnMerge(metaColumn.Type.scriptingType, parentViewTable, row, column.GetColumn(), metaColumn); column.SetEntry(row, expression, null); } }
public IViewColumn Build(ViewTable.Builder.BuildingData buildingData, ViewTable.Builder.Node node, ViewTable vTable, Operation.ExpressionParsingContext expressionParsingContext, ref Database.MetaColumn metaColumn) { // Check if we have a type mismatch Type columnValueType = metaColumn != null ? metaColumn.Type.scriptingType : null; if (value != null && value.type != null) { if (columnValueType != null && columnValueType != value.type) { Debug.LogWarning("While building column '" + name + "' : " + "Cannot override type from '" + columnValueType.Name + "' to '" + value.type.Name + "'"); } columnValueType = value.type; } // Parse expression value Operation.Expression.ParseIdentifierOption parseOpt = new Operation.Expression.ParseIdentifierOption(buildingData.Schema, vTable, true, false, columnValueType, expressionParsingContext); parseOpt.formatError = (string s, Operation.Expression.ParseIdentifierOption opt) => { return(FormatErrorContextInfo(buildingData.Schema, vTable) + " : " + s); }; Operation.Expression expression = Operation.Expression.ParseIdentifier(value, parseOpt); // Build declaration with the type we've just parsed BuildOrUpdateDeclaration(buildingData, vTable, ref metaColumn, expressionParsingContext, expression.type); IViewColumn result = (IViewColumn)Operation.ColumnCreator.CreateViewColumnExpression(expression); ViewColumn vc = new ViewColumn(); vc.m_MetaLink = m_MetaLink; vc.viewTable = vTable; vc.ParsingContext = expressionParsingContext; result.SetColumn(vc, null); return(result); }