コード例 #1
0
ファイル: Algebrizer.cs プロジェクト: chenzuo/nquery
		private bool IsTableReferenceToCurrentCommonTableBinding(TableReference tableReference)
		{
			NamedTableReference namedTableReference = tableReference as NamedTableReference;
			if (namedTableReference == null)
				return false;

			return namedTableReference.TableRefBinding.TableBinding == _currentCommonTableBinding;
		}
コード例 #2
0
        public override string GenerateMostRestrictiveTableQuery(TableReference table, bool includePrimaryKey, int top)
        {
            // Normalize search conditions and extract where clause
            var cn = new SearchConditionNormalizer();
            cn.NormalizeQuerySpecification(((TableSource)table.Node).QuerySpecification);
            var where = cn.GenerateWhereClauseSpecificToTable(table);

            // Build table specific query
            var sql = new StringWriter();

            sql.Write("SELECT ");

            // Now write the referenced columns
            int q = 0;
            foreach (var cr in table.ColumnReferences.Where(c => c.IsReferenced))
            {
                if (q != 0)
                {
                    sql.Write(", ");
                }

                if (cr.DataType.IsInteger)
                {
                    // Here a cast to a type that is accepted by SQL Server has to be made
                    sql.Write("CAST(`{0}` AS SIGNED) AS `{0}`", cr.ColumnName);
                }
                else
                {
                    sql.Write("`{0}`", cr.ColumnName);
                }
                q++;
            }

            // From cluse
            sql.Write(" FROM `{0}`", table.DatabaseObjectName);
            if (table.Alias != null)
            {
                sql.Write(" `{0}`", table.Alias);
            }
            sql.Write(" ");

            if (where != null)
            {
                Execute(sql, where);
            }

            if (top > 0)
            {
                sql.Write(" LIMIT {0} ", top);
            }

            return sql.ToString();
        }
コード例 #3
0
        public override string GenerateMostRestrictiveTableQuery(TableReference table, bool includePrimaryKey, int top)
        {
            // Normalize search conditions and extract where clause
            var cn = new SearchConditionNormalizer();
            cn.NormalizeQuerySpecification(((TableSource)table.Node).QuerySpecification);
            var where = cn.GenerateWhereClauseSpecificToTable(table);

            // Build table specific query
            var sql = new StringWriter();

            sql.Write("SELECT ");

            // Now write the referenced columns
            int q = 0;
            foreach (var cr in table.ColumnReferences.Where(c => c.IsReferenced))
            {
                if (q != 0)
                {
                    sql.Write(", ");
                }

                sql.Write("{0}", QuoteIdentifier(cr.ColumnName));
                q++;
            }

            // From cluse
            sql.Write(" FROM {0}", QuoteIdentifier(table.DatabaseObjectName));
            if (table.Alias != null)
            {
                sql.Write(" {0}", QuoteIdentifier(table.Alias));
            }
            sql.Write(" ");

            if (where != null)
            {
                Execute(sql, where);
            }

            if (top > 0)
            {
                sql.Write(" LIMIT {0} ", top);
            }

            return sql.ToString();
        }
コード例 #4
0
 /// <summary>
 /// Asynchronously deletes the specified table.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation.</returns>
 public virtual Task DeleteTableAsync(TableReference tableReference, DeleteTableOptions options = null, CancellationToken cancellationToken = default) =>
 throw new NotImplementedException();
コード例 #5
0
 /// <summary>
 /// Creates the specified table.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="schema">The schema for the new table. Must not be null unless the schema can be inferred (e.g. for a view).</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The newly created table.</returns>
 public virtual BigQueryTable CreateTable(TableReference tableReference, TableSchema schema, CreateTableOptions options = null) =>
 throw new NotImplementedException();
コード例 #6
0
 /// <summary>
 /// Asynchronously attempts to fetch the specified table, creating it if it doesn't exist.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="schema">The schema to use to create the table if necessary. Must not be null unless the schema can be inferred (e.g. for a view).</param>
 /// <param name="getOptions">The options for the "get" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="createOptions">The options for the "create" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the existing or new table.</returns>
 public virtual Task <BigQueryTable> GetOrCreateTableAsync(TableReference tableReference, TableSchema schema, GetTableOptions getOptions = null, CreateTableOptions createOptions = null, CancellationToken cancellationToken = default) =>
 throw new NotImplementedException();
コード例 #7
0
        /// <inheritdoc />
        public override async Task <BigQueryJob> CreateLoadJobAsync(IEnumerable <string> sourceUris, TableReference destination, TableSchema schema, CreateLoadJobOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var job = await CreateLoadJobRequest(sourceUris, destination, schema, options).ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BigQueryJob(this, job));
        }
コード例 #8
0
            private void AddReference(Dictionary <string, EnumLookupTable> enumSet, EnumType enumType, TableReference reference)
            {
                EnumLookupTable entry;

                if (enumSet.TryGetValue(enumType.FullName, out entry))
                {
                    entry.References.Add(reference);
                }
                else
                {
                    var enumInfo = new EnumLookupTable(enumType, reference);
                    enumSet.Add(enumType.FullName, enumInfo);
                }
            }
コード例 #9
0
ファイル: MappingGenerator.cs プロジェクト: DelLitt/opmscoral
        private void AddOneToManyProperty(XmlDocument xmldoc, XmlElement classElement, TableReference reference)
        {
            string refTableName = GlobalCache.Instance.ReplaceShortWords(reference.ReferenceTable.ToUpper());
                refTableName = refTableName.GetFormattedText();
                var xmlNode = xmldoc.CreateElement("bag");
                //xmlNode.SetAttribute("lazy", "true");
                xmlNode.SetAttribute("inverse", "true");
                xmlNode.SetAttribute("name", refTableName + "s");

                var xmlKeyNode = xmldoc.CreateElement("key");
                foreach (KeyValuePair<ColumnDetail,ColumnDetail> refColumn in reference.TableColumns)
                {
                    var xmlColumn = xmldoc.CreateElement("column");
                    xmlColumn.SetAttribute("name", refColumn.Key.ColumnName);
                    xmlKeyNode.AppendChild(xmlColumn);
                }
                xmlNode.AppendChild(xmlKeyNode);

                var xmlRefType = xmldoc.CreateElement("one-to-many");
                xmlRefType.SetAttribute("class", refTableName);
                xmlNode.AppendChild(xmlRefType);

                classElement.AppendChild(xmlNode);
        }
コード例 #10
0
        private void ProcessTableReference(TableReference TableRef, WithCtesAndXmlNamespaces cte)
        {
            string Type = FragmentTypeParser.GetFragmentType(TableRef);
            switch (Type)
            {
                case "NamedTableReference":
                    var NamedTableRef = (NamedTableReference) TableRef;
                    if (NamedTableRef.SchemaObject.BaseIdentifier.Value[0] != '#' &&
                        NamedTableRef.SchemaObject.BaseIdentifier.Value[0] != '@')
                    {
                        if (NamedTableRef.SchemaObject.ServerIdentifier != null)
                        {
                            _smells.SendFeedBack(1, NamedTableRef);
                        }
                        if (NamedTableRef.SchemaObject.SchemaIdentifier == null &&
                            !isCteName(NamedTableRef.SchemaObject, cte))
                        {
                            _smells.SendFeedBack(2, NamedTableRef);
                        }
                    }
                    if (NamedTableRef.TableHints != null)
                    {
                        foreach (TableHint TableHint in NamedTableRef.TableHints)
                        {
                            switch (TableHint.HintKind)
                            {
                                case TableHintKind.NoLock:
                                    _smells.SendFeedBack(3, TableHint);
                                    break;
                                case TableHintKind.ReadPast:
                                    break;
                                case TableHintKind.ForceScan:
                                    _smells.SendFeedBack(44, TableHint);
                                    break;
                                case TableHintKind.Index:
                                    _smells.SendFeedBack(45, TableHint);
                                    break;
                                default:
                                    _smells.SendFeedBack(4, TableHint);
                                    break;
                            }
                        }
                    }
                    break;
                case "QueryDerivedTable":

                    var QueryDerivedRef = (QueryDerivedTable) TableRef;
                    String Alias = QueryDerivedRef.Alias.Value;
                    if (Alias.Length == 1)
                    {
                        _smells.SendFeedBack(11, QueryDerivedRef);
                    }
                    if (FragmentTypeParser.GetFragmentType(QueryDerivedRef.QueryExpression) == "QuerySpecification")
                    {
                        //    QuerySpecification QuerySpec = (QuerySpecification)QueryDerivedRef.QueryExpression;
                        //  Process(QuerySpec.FromClause, cte);
                        _smells.ProcessQueryExpression(QueryDerivedRef.QueryExpression, "RG", true, cte);
                    }
                    break;
                case "QualifiedJoin":
                    var QualifiedJoin = (QualifiedJoin) TableRef;
                    ProcessTableReference(QualifiedJoin.FirstTableReference, cte);
                    ProcessTableReference(QualifiedJoin.SecondTableReference, cte);
                    break;
            }
        }
コード例 #11
0
        private void ProcessTableReference(TableReference TableRef)
        {
            string Type = GetFragmentType(TableRef);
            switch (Type)
            {
                case "FullTextTableReference":
                    break;
                case "NamedTableReference":
                    var NamedTableRef = (NamedTableReference)TableRef;
                    var Naming = NamedTableRef.SchemaObject;
                    string ObjectName = (Naming.DatabaseIdentifier == null ? this.databaseName : Naming.DatabaseIdentifier.Value) + "." +
                        (Naming.SchemaIdentifier == null ? this.schemaName : Naming.SchemaIdentifier.Value) + "." +
                        (Naming.BaseIdentifier == null ? "" : Naming.BaseIdentifier.Value);
                    addSourcetoCurrentObject(ObjectName);

                    break;
                case "QueryDerivedTable":
                    QueryDerivedTable qdt = (QueryDerivedTable)TableRef;
                    ProcessQueryExpression(qdt.QueryExpression);
                    break;
                case "QualifiedJoin":
                    QualifiedJoin qj = (QualifiedJoin)TableRef;
                    ProcessTableReference(qj.FirstTableReference);
                    ProcessTableReference(qj.SecondTableReference);
                    break;
                case "UnqualifiedJoin":
                    UnqualifiedJoin uqj = (UnqualifiedJoin)TableRef;
                    ProcessTableReference(uqj.FirstTableReference);
                    ProcessTableReference(uqj.SecondTableReference);
                    break;
                case "SchemaObjectFunctionTableReference":
                    SchemaObjectFunctionTableReference ftr = (SchemaObjectFunctionTableReference)TableRef;
                    break;
                case "PivotedTableReference":
                    PivotedTableReference pvt = (PivotedTableReference)TableRef;
                    ProcessTableReference(pvt.TableReference);
                    break;
                default:
                    break;
            }
        }
コード例 #12
0
        public override string GenerateMostRestrictiveTableQuery(TableReference table, bool includePrimaryKey, int top)
        {
            // Normalize search conditions and extract where clause
            var cn = new SearchConditionNormalizer();
            cn.NormalizeQuerySpecification(((TableSource)table.Node).QuerySpecification);
            var where = cn.GenerateWhereClauseSpecificToTable(table);

            // Build table specific query
            var sql = new StringWriter();

            sql.Write("SELECT ");

            if (top > 0)
            {
                sql.Write("TOP {0} ", top);
            }

            // Now write the referenced columns
            var referencedcolumns = new HashSet<string>(Jhu.Graywulf.Schema.SqlServer.SqlServerSchemaManager.Comparer);

            int q = 0;
            if (includePrimaryKey)
            {
                var t = table.DatabaseObject as Jhu.Graywulf.Schema.Table;
                foreach (var cr in t.PrimaryKey.Columns.Values)
                {
                    var columnname = String.Format(
                        "{0}.{1}",
                        QuoteIdentifier(table.Alias),
                        QuoteIdentifier(cr.ColumnName));

                    if (!referencedcolumns.Contains(columnname))
                    {
                        if (q != 0)
                        {
                            sql.Write(", ");
                        }
                        sql.Write(columnname);
                        q++;

                        referencedcolumns.Add(columnname);
                    }
                }
            }

            foreach (var cr in table.ColumnReferences.Where(c => c.IsReferenced))
            {
                var columnname = GetResolvedColumnName(cr);     // TODO: verify

                if (!referencedcolumns.Contains(columnname))
                {
                    if (q != 0)
                    {
                        sql.Write(", ");
                    }
                    sql.Write(columnname);
                    q++;

                    referencedcolumns.Add(columnname);
                }
            }

            // From cluse
            sql.Write(" FROM {0} ", GetResolvedTableName(table));
            if (!String.IsNullOrWhiteSpace(table.Alias))
            {
                sql.Write("AS {0} ", QuoteIdentifier(table.Alias));
            }

            if (where != null)
            {
                Execute(sql, where);
            }

            return sql.ToString();
        }
コード例 #13
0
        /// <inheritdoc />
        public override async Task <BigQueryJob> CreateCopyJobAsync(IEnumerable <TableReference> sources, TableReference destination, CreateCopyJobOptions options = null, CancellationToken cancellationToken = default)
        {
            var job = await CreateCopyJobRequest(sources, destination, options).ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BigQueryJob(this, job));
        }
コード例 #14
0
 /// <summary>
 /// Add a platform override for the current table collection.
 /// This will result in the table being switched but the same entry name being used.
 /// This is useful if you want to have specialist tables that will implement the same keys for certain entries.
 /// </summary>
 /// <example>
 /// This example shows how you could set up platform overrides using a table for each platform.
 /// <code source="../../DocCodeSamples.Tests/PlatformOverrideExamples.cs" region="table-override"/>
 /// </example>
 /// <param name="platform">The platform to override.</param>
 /// <param name="table">The table collection to use instead of the current one.</param>
 public void AddPlatformTableOverride(RuntimePlatform platform, TableReference table) => AddPlatformOverride(platform, table, default, EntryOverrideType.Table);
コード例 #15
0
 private void OnAsyncExecute(Guid workflowInstanceGuid, string activityInstanceId, QueryPartitionBase querypartition, TableReference remotetable, SourceTableQuery source)
 {
     RegisterCancelable(workflowInstanceGuid, activityInstanceId, querypartition);
     querypartition.CopyRemoteTable(remotetable, source);
     UnregisterCancelable(workflowInstanceGuid, activityInstanceId, querypartition);
 }
 public AssetTableCollection FindAssetTableCollection(TableReference tableReference) => FindTableCollection(AssetTableCollections, tableReference);
コード例 #17
0
        public override string GenerateMostRestrictiveTableQuery(SelectStatement selectStatement, TableReference table, int top)
        {
            // Function assumes that Condition Normalizer has already run on the query
            // *** TODO: check this using flags ^^^^

            var sql = new StringWriter();

            sql.Write("SELECT ");

            // Now write the referenced columns
            int q = 0;
            foreach (var cr in table.ColumnReferences.Where(c => c.IsReferenced))
            {
                if (q != 0)
                {
                    sql.Write(", ");
                }
                sql.Write("`{0}`", cr.ColumnName);
                q++;
            }

            // From cluse
            sql.Write(" FROM `{0}`", table.TableName);
            if (!String.IsNullOrWhiteSpace(table.Alias))
            {
                sql.Write(" `{0}`", table.Alias);
            }

            // Generate the table specific most restictive where clause
            var cnr = new SearchConditionNormalizer();
            cnr.Execute(selectStatement.EnumerateQuerySpecifications().First());        // TODO: what if more than one QS?
            var where = cnr.GenerateWhereClauseSpecificToTable(table);
            if (where != null)
            {
                Execute(sql, where);
            }

            if (top > 0)
            {
                sql.Write(" LIMIT {0} ", top);
            }

            return sql.ToString();
        }
コード例 #18
0
 /// <summary>
 /// Lists the rows within a table, similar to a <c>SELECT * FROM ...</c> query.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="schema">The schema to use when interpreting results. This may be null, in which case it will be fetched from
 /// the table first.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>An asynchronous sequence of the rows within the table.</returns>
 public virtual PagedAsyncEnumerable <TableDataList, BigQueryRow> ListRowsAsync(TableReference tableReference, TableSchema schema = null, ListRowsOptions options = null)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 // Note - these methods are not part of the regular "pattern", so are not in the GetQueryResults region above.
 // We want to remove them, if the underlying GetQueryResultsResponse starts including the table reference.
 // These methods allow us to call GetQueryResultsAsync from BigQueryJob without fetching the job again.
 internal virtual BigQueryResults GetQueryResults(JobReference jobReference, TableReference tableReference, GetQueryResultsOptions options) =>
 throw new NotImplementedException();
コード例 #20
0
 public override void ExplicitVisit(TableReference fragment)
 {
     _fragments.Add(fragment);
 }
コード例 #21
0
 internal virtual Task <BigQueryResults> GetQueryResultsAsync(JobReference jobReference, TableReference tableReference, GetQueryResultsOptions options, CancellationToken cancellationToken) =>
 throw new NotImplementedException();
コード例 #22
0
 private void AddReference(Dictionary<string, EnumLookupTable> enumSet, EnumType enumType, TableReference reference)
 {
    EnumLookupTable entry;
    if (enumSet.TryGetValue(enumType.FullName, out entry))
    {
       entry.References.Add(reference);
    } else
    {
       var enumInfo = new EnumLookupTable(enumType, reference);
       enumSet.Add(enumType.FullName, enumInfo);
    }
 }
コード例 #23
0
 /// <summary>
 /// Creates a table with the given schema.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="schema">The schema for the new table. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the newly created table.</returns>
 public virtual Task <BigQueryTable> CreateTableAsync(TableReference tableReference, TableSchema schema, CreateTableOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #24
0
        private string QuoteTableReferenceName(TableReference tableReference)
        {
            string res = String.Empty;

            if (tableReference != null)
            {
                if (tableReference.Alias == null)
                {
                    if (tableReference.IsUdf || tableReference.IsSubquery || tableReference.IsComputed)
                    {
                        res = QuoteIdentifier(tableReference.Alias);
                    }
                    else
                    {
                        if (tableReference.DatabaseObject != null)
                        {
                            if (tableReference.DatabaseObject.ObjectName != null) res += QuoteIdentifier(tableReference.DatabaseObject.ObjectName);
                        }
                        else
                        {
                            //if (tableReference.DatabaseName != null) res += String.Format("`{0}`.", tableReference.DatabaseName);
                            if (tableReference.DatabaseObjectName != null) res += QuoteIdentifier(tableReference.DatabaseObjectName);
                        }
                    }
                }
                else
                {
                    res = QuoteIdentifier(tableReference.Alias);
                }
            }

            return res;
        }
コード例 #25
0
ファイル: SqlQueryParser.cs プロジェクト: tinydyw/DataPithy
 protected virtual void ParseTable(TableReference table)
 {
     Builder.AppendName(table.TableName);
 }
コード例 #26
0
            public ICollection <EnumLookupTable> GetEnumLookupTables()
            {
                var conceptualEntityContainer = _workspace
                                                .GetItems <EntityContainer>(DataSpace.CSpace)
                                                .Single();

                var mappings = _workspace.GetItems <EntityContainerMapping>(DataSpace.CSSpace)
                               .Single()
                               .EntitySetMappings
                               .ToList();

                var enumSet = new Dictionary <string, EnumLookupTable>();

                foreach (var conceptualEntitySet in conceptualEntityContainer.EntitySets)
                {
                    var mappingFragment = mappings.Single(x => x.EntitySet == conceptualEntitySet)
                                          .EntityTypeMappings.Single()
                                          .Fragments.Single();

                    var tableName   = mappingFragment.StoreEntitySet.Table;
                    var tableSchema = mappingFragment.StoreEntitySet.Schema;

                    foreach (var property in conceptualEntitySet.ElementType.Properties)
                    {
                        if (property.IsEnumType)
                        {
                            var propertyMapping = (ScalarPropertyMapping)mappingFragment.PropertyMappings
                                                  .Single(x => x.Property.Name == property.Name);

                            var reference = new TableReference
                            {
                                TableName   = tableName,
                                TableSchema = tableSchema,
                                ColumnName  = propertyMapping.Column.Name
                            };

                            AddReference(enumSet, property.EnumType, reference);
                        }
                        else if (property.IsComplexType)
                        {
                            var complexPropertyMapping = ((ComplexPropertyMapping)mappingFragment.PropertyMappings
                                                          .Single(x => x.Property.Name == property.Name));

                            foreach (var complexTypeProperty in property.ComplexType.Properties)
                            {
                                if (complexTypeProperty.IsEnumType)
                                {
                                    var propertyMapping = (ScalarPropertyMapping)complexPropertyMapping
                                                          .TypeMappings
                                                          .SelectMany(x => x.PropertyMappings)
                                                          .Single(x => x.Property.Name == complexTypeProperty.Name);

                                    var reference = new TableReference
                                    {
                                        TableName   = tableName,
                                        TableSchema = tableSchema,
                                        ColumnName  = propertyMapping.Column.Name
                                    };

                                    AddReference(enumSet, complexTypeProperty.EnumType, reference);
                                }
                            }
                        }
                    }
                }

                return(enumSet.Values);
            }
コード例 #27
0
        internal override async Task <BigQueryResults> GetQueryResultsAsync(JobReference jobReference, TableReference tableReference, GetQueryResultsOptions options, CancellationToken cancellationToken)
        {
            GaxPreconditions.CheckNotNull(jobReference, nameof(jobReference));
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            // This validates the options before we make any RPCs
            var listRowsOptions = options?.ToListRowsOptions();

            DateTime start = Clock.GetCurrentDateTimeUtc();

            while (true)
            {
                // This will throw if the query has timed out.
                var request  = CreateGetQueryResultsRequest(jobReference, options, start);
                var response = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);

                if (response.JobComplete == true)
                {
                    return(new BigQueryResults(this, response, tableReference, listRowsOptions));
                }
            }
        }
コード例 #28
0
            public EnumLookupTable(EnumType enumType, TableReference reference)
            {
                EnumType = enumType;
                Rows     = new List <EnumLookupTableRow>();
                if (enumType.IsFlags)
                {
                    foreach (var enumField in enumType.Members)
                    {
                        var enumValue = enumField.Value;
                        switch (enumType.UnderlyingType.PrimitiveTypeKind)
                        {
                        case PrimitiveTypeKind.Byte:
                        case PrimitiveTypeKind.SByte:
                            if (((byte)enumValue & ((byte)enumValue - 1)) != 0)
                            {
                                // composed enum value
                                continue;
                            }
                            break;

                        case PrimitiveTypeKind.Int16:
                            if (((short)enumValue & ((short)enumValue - 1)) != 0)
                            {
                                // composed enum value
                                continue;
                            }
                            break;

                        case PrimitiveTypeKind.Int32:
                            if (((int)enumValue & ((int)enumValue - 1)) != 0)
                            {
                                // composed enum value
                                continue;
                            }
                            break;

                        case PrimitiveTypeKind.Int64:
                            if (((long)enumValue & ((long)enumValue - 1)) != 0)
                            {
                                // composed enum value
                                continue;
                            }
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        var name = enumField.Name.SeparateWords();

                        Rows.Add(new EnumLookupTableRow
                        {
                            Id   = enumValue.ToString(),
                            Name = name
                        });
                    }
                }
                else
                {
                    foreach (var enumField in enumType.Members)
                    {
                        var enumValue = enumField.Value.ToString();
                        var name      = enumField.Name.SeparateWords();

                        Rows.Add(new EnumLookupTableRow
                        {
                            Id   = enumValue,
                            Name = name
                        });
                    }
                }

                References = new List <TableReference>
                {
                    reference
                };
            }
コード例 #29
0
        /// <inheritdoc />
        public override PagedAsyncEnumerable <TableDataList, BigQueryRow> ListRowsAsync(TableReference tableReference, TableSchema schema = null, ListRowsOptions options = null)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            // TODO: This is a synchronous call. We can't easily make this part asynchronous - we don't have a cancellation token, and we're returning
            // a non-task value. We could defer until the first MoveNext call, but that's tricky.
            schema = schema ?? GetSchema(tableReference);

            var pageManager = new TableRowPageManager(this, schema);

            return(new RestPagedAsyncEnumerable <TabledataResource.ListRequest, TableDataList, BigQueryRow>(
                       () => CreateListRequest(tableReference, options), pageManager));
        }
コード例 #30
0
 /// <summary>
 /// Attempts to fetch the specified table, creating it if it doesn't exist.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="schema">The schema to use to create the table if necessary. Must not be null unless the schema can be inferred (e.g. for a view).</param>
 /// <param name="getOptions">The options for the "get" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="createOptions">The options for the "create" operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The existing or new table.</returns>
 public virtual BigQueryTable GetOrCreateTable(TableReference tableReference, TableSchema schema, GetTableOptions getOptions = null, CreateTableOptions createOptions = null) =>
 throw new NotImplementedException();
コード例 #31
0
        /// <summary>
        /// Populate the document with the entries from <paramref name="target"/> using <paramref name="source"/> as the source reference.
        /// Note: The source and target tables must be part of the same collection, they must both use the same <see cref="SharedTableData"/>.
        /// </summary>
        /// <param name="document">The XLIFF document to add the entries to.</param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void AddTableToDocument(IXliffDocument document, StringTable source, StringTable target)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (source.SharedData != target.SharedData)
            {
                throw new Exception("Source and Target StringTables must be part of the same collection and use the same SharedTableData.");
            }

            var file     = document.AddNewFile();
            var filePath = AssetDatabase.GetAssetPath(target);

            file.Original = filePath;
            file.Id       = AssetDatabase.AssetPathToGUID(filePath);

            var group = file.AddNewGroup();

            group.Id   = TableReference.StringFromGuid(target.SharedData.TableCollectionNameGuid);
            group.Name = target.SharedData.TableCollectionName;

            AddNotesFromMetadata(group, target.SharedData.Metadata, NoteType.General);
            AddNotesFromMetadata(group, source, NoteType.Source);

            if (source != target)
            {
                AddNotesFromMetadata(group, target, NoteType.Target);
            }

            foreach (var row in StringTableCollection.GetRowEnumerator(source, target))
            {
                if (row.TableEntries[0].SharedEntry.Metadata.HasMetadata <ExcludeEntryFromExport>())
                {
                    continue;
                }

                var unit = group.AddNewTranslationUnit();

                unit.Id     = row.KeyEntry.Id.ToString();
                unit.Name   = row.KeyEntry.Key;
                unit.Source = row.TableEntries[0]?.Value;

                // Dont add a value if its empty.
                if (row.TableEntries[1] != null && !string.IsNullOrEmpty(row.TableEntries[1].Value))
                {
                    unit.Target = row.TableEntries[1].Value;
                }

                // Add notes
                AddNotesFromMetadata(unit, row.KeyEntry.Metadata, NoteType.General);
                AddNotesFromMetadata(unit, row.TableEntries[0], NoteType.Source);

                if (source != target)
                {
                    AddNotesFromMetadata(unit, row.TableEntries[1], NoteType.Target);
                }
            }
        }
コード例 #32
0
 /// <summary>
 /// Deletes the specified table.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 public virtual void DeleteTable(TableReference tableReference, DeleteTableOptions options = null) =>
 throw new NotImplementedException();
コード例 #33
0
 public override Table GetTableByReference(TableReference tableRef)
 {
     return(GetTableByName(tableRef.Name, tableRef.Param));
 }
コード例 #34
0
 /// <summary>
 /// Updates the specified table to match the specified resource.
 /// </summary>
 /// <remarks>
 /// If the resource contains an ETag, it is used for optimistic concurrency validation.
 /// </remarks>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="resource">The table resource representation to use for the update. All updatable fields will be updated.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The updated table.</returns>
 public virtual BigQueryTable UpdateTable(TableReference tableReference, Table resource, UpdateTableOptions options = null) =>
 throw new NotImplementedException();
コード例 #35
0
 /// <summary>
 /// Retrieves the specified table.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The requested table.</returns>
 public virtual BigQueryTable GetTable(TableReference tableReference, GetTableOptions options = null) =>
 throw new NotImplementedException();
コード例 #36
0
        private string GetResolvedTableName(TableReference table)
        {
            if (table.IsSubquery || table.IsComputed)
            {
                return QuoteIdentifier(table.Alias);
            }
            else
            {
                // If it is linked up to the schema, return
                if (table.DatabaseObject != null)
                {
                    return table.DatabaseObject.GetFullyResolvedName();
                }
                else
                {
                    string res = String.Empty;

                    // If it's not resolved yet
                    if (table.DatabaseName != null) res += QuoteIdentifier(table.DatabaseName) + ".";
                    if (table.SchemaName != null) res += QuoteIdentifier(table.SchemaName) + ".";
                    if (table.DatabaseObjectName != null) res += QuoteIdentifier(table.DatabaseObjectName);

                    return res;
                }
            }
        }
コード例 #37
0
 /// <summary>
 /// Asynchronously retrieves the specified table.
 /// </summary>
 /// <param name="tableReference">A fully-qualified identifier for the table. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the requested table.</returns>
 public virtual Task <BigQueryTable> GetTableAsync(TableReference tableReference, GetTableOptions options = null, CancellationToken cancellationToken = default) =>
 throw new NotImplementedException();
コード例 #38
0
ファイル: StandardVisitor.cs プロジェクト: chenzuo/nquery
		public virtual TableReference VisitTableReference(TableReference node)
		{
			return (TableReference)Visit(node);
		}
コード例 #39
0
        /// <inheritdoc />
        public override BigQueryJob CreateExtractJob(TableReference tableReference, IEnumerable <string> destinationUris, CreateExtractJobOptions options = null)
        {
            var job = CreateExtractJobRequest(tableReference, destinationUris, options).Execute();

            return(new BigQueryJob(this, job));
        }
コード例 #40
0
        public string GenerateTableStatisticsQuery(TableReference table)
        {
            if (table.Statistics == null)
            {
                throw new InvalidOperationException();
            }

            // Build table specific where clause
            var cnr = new SearchConditionNormalizer();
            cnr.NormalizeQuerySpecification(((TableSource)table.Node).QuerySpecification);
            var wh = cnr.GenerateWhereClauseSpecificToTable(table);

            var where = new StringWriter();
            if (wh != null)
            {
                var cg = new SqlServerCodeGenerator();
                cg.Execute(where, wh);
            };

            //*** TODO: move into resource
            string sql = String.Format(@"
            IF OBJECT_ID('tempdb..##keys_{4}') IS NOT NULL
            DROP TABLE ##keys_{4}

            SELECT CAST({2} AS float) AS __key
            INTO ##keys_{4}
            FROM {0} {1}
            {3};

            DECLARE @count bigint = @@ROWCOUNT;
            DECLARE @step bigint = @count / @bincount;

            IF (@step = 0) SET @step = NULL;

            WITH q AS
            (
            SELECT __key, ROW_NUMBER() OVER (ORDER BY __key) __rn
            FROM ##keys_{4}
            )
            SELECT __key, __rn
            FROM q
            WHERE __rn % @step = 1 OR __rn = @count;

            DROP TABLE ##keys_{4};
            ",
             GetResolvedTableName(table),
             table.Alias == null ? "" : String.Format(" AS {0} ", QuoteIdentifier(table.Alias)),
             QuoteIdentifier(table.Statistics.KeyColumn),
             where.ToString(),
             Guid.NewGuid().ToString().Replace('-', '_'));

            return sql;
        }
コード例 #41
0
        /// <inheritdoc />
        public override async Task <BigQueryJob> CreateExtractJobAsync(TableReference tableReference, IEnumerable <string> destinationUris, CreateExtractJobOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var job = await CreateExtractJobRequest(tableReference, destinationUris, options).ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BigQueryJob(this, job));
        }
コード例 #42
0
ファイル: MappingGenerator.cs プロジェクト: DelLitt/opmscoral
        private void AddManyToOneProperty(XmlDocument xmldoc, XmlElement classElement, TableReference reference)
        {
            string refTableName = GlobalCache.Instance.ReplaceShortWords(reference.ReferenceTable.ToUpper());
            refTableName = refTableName.GetFormattedText();
            var xmlNode = xmldoc.CreateElement("many-to-one");
            //xmlNode.SetAttribute("lazy", "true");
            /*xmlNode.SetAttribute("update", "false");
            xmlNode.SetAttribute("insert", "false");*/
            xmlNode.SetAttribute("class", refTableName);
            xmlNode.SetAttribute("name", refTableName);

            foreach (KeyValuePair<ColumnDetail, ColumnDetail> refColumn in reference.TableColumns)
            {
                var xmlColumn = xmldoc.CreateElement("column");
                xmlColumn.SetAttribute("name", refColumn.Key.ColumnName);

                // if foreign column differ with primary key
                if(!refColumn.Key.Equals(refColumn.Value.ColumnName))
                {
                    string primaryColName = refColumn.Value.ColumnName;
                    ApplicationPreferences primaryKeys =
                        GlobalCache.Instance.TablePreferences.
                            Find(pref => pref.TableName.Equals(reference.ReferenceTable));
                    if (primaryKeys == null) throw new Exception("Reference table " + reference.ReferenceTable + "does not exist for " + tableName + " !");
                    var metadataReader = GlobalCache.Instance.MetaDataReader;
                    ColumnDetails primaryDetails = metadataReader.GetTableDetails(primaryKeys.TableName);
                    List<ColumnDetail> priKeys = primaryDetails.FindAll(col => col.IsPrimaryKey);

                    if(priKeys.Find( col =>col.ColumnName.Equals(primaryColName)) != null)
                    {
                        if(priKeys.Count == 1)
                        {
                            string realPriPrefColName = primaryColName.GetFormattedText();
                            //xmlColumn.SetAttribute("property-ref", realPriPrefColName);
                        }
                        else if(priKeys.Count > 1)
                        {
                            string priCompositePK = GlobalCache.Instance.ReplaceShortWords(primaryKeys.TableName.ToUpper());
                            priCompositePK = priCompositePK.GetFormattedText() + "PK";
                            xmlNode.SetAttribute("property-ref", priCompositePK);
                            //xmlColumn.SetAttribute("property-ref", primaryColName.GetFormattedText());
                        }
                    }
                    else
                    {
                        if (primaryDetails.Find(col => col.ColumnName.Equals(primaryColName)) != null)
                        {
                            //xmlColumn.SetAttribute("property-ref", primaryColName.GetFormattedText());
                        }
                    }

                }
                xmlNode.AppendChild(xmlColumn);
            }

            classElement.AppendChild(xmlNode);
        }
コード例 #43
0
        /// <inheritdoc />
        public override BigQueryJob CreateCopyJob(IEnumerable <TableReference> sources, TableReference destination, CreateCopyJobOptions options = null)
        {
            var job = CreateCopyJobRequest(sources, destination, options).Execute();

            return(new BigQueryJob(this, job));
        }
コード例 #44
0
         public ICollection<EnumLookupTable> GetEnumLookupTables()
         {
            var conceptualEntityContainer = _workspace
               .GetItems<EntityContainer>(DataSpace.CSpace)
               .Single();

            var mappings = _workspace.GetItems<EntityContainerMapping>(DataSpace.CSSpace)
               .Single()
               .EntitySetMappings
               .ToList();

            var enumSet = new Dictionary<string, EnumLookupTable>();

            foreach (var conceptualEntitySet in conceptualEntityContainer.EntitySets)
            {
               var mappingFragment = mappings.Single(x => x.EntitySet == conceptualEntitySet)
                  .EntityTypeMappings.Single()
                  .Fragments.Single();

               var tableName = mappingFragment.StoreEntitySet.Table;
               var tableSchema = mappingFragment.StoreEntitySet.Schema;

               foreach (var property in conceptualEntitySet.ElementType.Properties)
               {
                  if (property.IsEnumType)
                  {
                     var propertyMapping = (ScalarPropertyMapping)mappingFragment.PropertyMappings
                        .Single(x => x.Property.Name == property.Name);

                     var reference = new TableReference
                     {
                        TableName = tableName,
                        TableSchema = tableSchema,
                        ColumnName = propertyMapping.Column.Name
                     };

                     AddReference(enumSet, property.EnumType, reference);

                  } else if (property.IsComplexType)
                  {
                     var complexPropertyMapping = ((ComplexPropertyMapping)mappingFragment.PropertyMappings
                        .Single(x => x.Property.Name == property.Name));

                     foreach (var complexTypeProperty in property.ComplexType.Properties)
                     {
                        if (complexTypeProperty.IsEnumType)
                        {
                           var propertyMapping = (ScalarPropertyMapping)complexPropertyMapping
                              .TypeMappings
                              .SelectMany(x => x.PropertyMappings)
                              .Single(x => x.Property.Name == complexTypeProperty.Name);

                           var reference = new TableReference
                           {
                              TableName = tableName,
                              TableSchema = tableSchema,
                              ColumnName = propertyMapping.Column.Name
                           };

                           AddReference(enumSet, complexTypeProperty.EnumType, reference);
                        }
                     }
                  }
               }
            }

            return enumSet.Values;
         }
コード例 #45
0
        private InsertRequest CreateCopyJobRequest(IEnumerable <TableReference> sources, TableReference destination, CreateCopyJobOptions options)
        {
            GaxPreconditions.CheckNotNull(sources, nameof(sources));
            GaxPreconditions.CheckNotNull(destination, nameof(destination));
            List <TableReference> sourceList = sources.ToList();

            GaxPreconditions.CheckArgument(sourceList.Count != 0, nameof(sources), "Sources cannot be empty");

            var copy = new JobConfigurationTableCopy {
                SourceTables = sourceList, DestinationTable = destination
            };

            options?.ModifyRequest(copy);
            var request = Service.Jobs.Insert(new Job
            {
                Configuration = new JobConfiguration
                {
                    Copy = copy
                }
            }, ProjectId);

            request.ModifyRequest += _versionHeaderAction;
            return(request);
        }
コード例 #46
0
         public EnumLookupTable(EnumType enumType, TableReference reference)
         {
            EnumType = enumType;
            Rows = new List<EnumLookupTableRow>();
            if (enumType.IsFlags)
            {
               foreach (var enumField in enumType.Members)
               {

                  var enumValue = enumField.Value;
                  switch (enumType.UnderlyingType.PrimitiveTypeKind)
                  {
                     case PrimitiveTypeKind.Byte:
                     case PrimitiveTypeKind.SByte:
                        if (((byte)enumValue & ((byte)enumValue - 1)) != 0)
                        {
                           // composed enum value
                           continue;
                        }
                        break;
                     case PrimitiveTypeKind.Int16:
                        if (((short)enumValue & ((short)enumValue - 1)) != 0)
                        {
                           // composed enum value
                           continue;
                        }
                        break;
                     case PrimitiveTypeKind.Int32:
                        if (((int)enumValue & ((int)enumValue - 1)) != 0)
                        {
                           // composed enum value
                           continue;
                        }
                        break;
                     case PrimitiveTypeKind.Int64:
                        if (((long)enumValue & ((long)enumValue - 1)) != 0)
                        {
                           // composed enum value
                           continue;
                        }
                        break;
                     default:
                        throw new ArgumentOutOfRangeException();
                  }

                  var name = enumField.Name.SeparateWords();

                  Rows.Add(new EnumLookupTableRow
                  {
                     Id = enumValue.ToString(),
                     Name = name
                  });
               }
            } else
            {
               foreach (var enumField in enumType.Members)
               {
                  var enumValue = enumField.Value.ToString();
                  var name = enumField.Name.SeparateWords();

                  Rows.Add(new EnumLookupTableRow
                  {
                     Id = enumValue,
                     Name = name
                  });
               }
            }

            References = new List<TableReference>
         {
            reference
         };
         }
コード例 #47
0
        /// <inheritdoc />
        public override BigQueryJob CreateLoadJob(IEnumerable <string> sourceUris, TableReference destination, TableSchema schema, CreateLoadJobOptions options = null)
        {
            var job = CreateLoadJobRequest(sourceUris, destination, schema, options).Execute();

            return(new BigQueryJob(this, job));
        }
コード例 #48
0
ファイル: WSqlParser.cs プロジェクト: Coword/GraphView
        private WTableReference ParseTableReference(TableReference tabRef)
        {
            if (tabRef == null)
            {
                return null;
            }
            var tabRefWithAlias = tabRef as TableReferenceWithAlias;
            if (tabRefWithAlias!=null && tabRefWithAlias.Alias!=null &&
                 GraphViewKeywords._keywords.Contains(tabRefWithAlias.Alias.Value))
            {
                var token = _tokens[tabRefWithAlias.Alias.FirstTokenIndex];
                throw new SyntaxErrorException(token.Line, tabRefWithAlias.Alias.Value,
                    "System restricted Name cannot be used");
            }
            switch (tabRef.GetType().Name)
            {
                case "NamedTableReference":
                    {
                        var oref = tabRef as NamedTableReference;
                        if (oref.SchemaObject.BaseIdentifier.QuoteType == QuoteType.NotQuoted &&
                            (oref.SchemaObject.BaseIdentifier.Value[0] == '@' ||
                             oref.SchemaObject.BaseIdentifier.Value[0] == '#'))
                        {
                            var pref = new WSpecialNamedTableReference
                            {
                                Alias = oref.Alias,
                                TableHints = new List<WTableHint>(),
                                FirstTokenIndex = oref.FirstTokenIndex,
                                LastTokenIndex = oref.LastTokenIndex,
                                TableObjectName = ParseSchemaObjectName(oref.SchemaObject),
                            };

                            if (oref.TableHints != null)
                            {
                                foreach (var hint in oref.TableHints)
                                    pref.TableHints.Add(ParseTableHint(hint));
                            }

                            return pref;
                        }
                        else
                        {
                            var pref = new WNamedTableReference
                            {
                                Alias = oref.Alias,
                                TableHints = new List<WTableHint>(),
                                FirstTokenIndex = oref.FirstTokenIndex,
                                LastTokenIndex = oref.LastTokenIndex,
                                TableObjectName = ParseSchemaObjectName(oref.SchemaObject),
                            };

                            if (oref.TableHints != null)
                            {
                                foreach (var hint in oref.TableHints)
                                    pref.TableHints.Add(ParseTableHint(hint));
                            }

                            return pref;
                        }
                    }
                case "QueryDerivedTable":
                    {
                        var oref = tabRef as QueryDerivedTable;
                        var pref = new WQueryDerivedTable
                        {
                            QueryExpr = ParseSelectQueryStatement(oref.QueryExpression),
                            Alias = oref.Alias,
                            Columns = oref.Columns,
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };

                        return pref;
                    }
                case "SchemaObjectFunctionTableReference":
                    {
                        var oref = tabRef as SchemaObjectFunctionTableReference;
                        var pref = new WSchemaObjectFunctionTableReference
                        {
                            Alias = oref.Alias,
                            Columns = oref.Columns,
                            SchemaObject = ParseSchemaObjectName(oref.SchemaObject),
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex
                        };
                        if (oref.Parameters == null)
                            return pref;
                        pref.Parameters = new List<WScalarExpression>();
                        foreach (var param in oref.Parameters)
                            pref.Parameters.Add(ParseScalarExpression(param));
                        return pref;
                    }
                case "QualifiedJoin":
                    {
                        var oref = tabRef as QualifiedJoin;
                        var pref = new WQualifiedJoin
                        {
                            FirstTableRef = ParseTableReference(oref.FirstTableReference),
                            SecondTableRef = ParseTableReference(oref.SecondTableReference),
                            QualifiedJoinType = oref.QualifiedJoinType,
                            JoinHint = oref.JoinHint,
                            JoinCondition = ParseBooleanExpression(oref.SearchCondition),
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };

                        return pref;
                    }
                case "UnqualifiedJoin":
                    {
                        var oref = tabRef as UnqualifiedJoin;
                        var pref = new WUnqualifiedJoin
                        {
                            FirstTableRef = ParseTableReference(oref.FirstTableReference),
                            SecondTableRef = ParseTableReference(oref.SecondTableReference),
                            UnqualifiedJoinType = oref.UnqualifiedJoinType,
                            FirstTokenIndex = oref.FirstTokenIndex,
                            LastTokenIndex = oref.LastTokenIndex,
                        };
                        return pref;
                    }
                case "JoinParenthesisTableReference":
                    {
                        var ptab = tabRef as JoinParenthesisTableReference;

                        var wptab = new WParenthesisTableReference
                        {
                            Table = ParseTableReference(ptab.Join),
                            FirstTokenIndex = ptab.FirstTokenIndex,
                            LastTokenIndex = ptab.LastTokenIndex,
                        };

                        return wptab;
                    }
                default:
                    return null;
            }
        }
コード例 #49
0
ファイル: AllNodesVisitor.cs プロジェクト: yaakoviyun/sqlskim
 public override void ExplicitVisit(TableReference node) { this.action(node); }