Ejemplo n.º 1
0
        public Task<bool> CreateTable(CreateTableRequest createTableRequest)
        {
            createTableRequest.CheckWhetherArgumentIsNull("createTableRequest");

            var createTablesUrl = this.urlBuilder.CreateTableUrl(createTableRequest.Database, createTableRequest.Table);

            return Task<bool>.Factory.StartNew(
                () =>
                {
                    using (var restService = this.webClientBuilder.BuildWebClient())
                    {
                        var requestJson = createTableRequest.ToJson();
                        var dictionaryResult = restService.PutJson<Dictionary<string, string>>(
                            createTablesUrl,
                            requestJson);

                        return dictionaryResult.ContainsKey("table") &&
                            dictionaryResult.ContainsValue(createTableRequest.Table) &&
                            dictionaryResult.ContainsKey("database") &&
                            dictionaryResult.ContainsValue(createTableRequest.Database);
                    }
                });
        }
Ejemplo n.º 2
0
        public void CreatesTableWithOneColumn()
        {
            // arrange
            this.CreateDatabaseIfNotExists();
            var uniqueTableName = BuildUniqueName();

            var createTableRequest = new CreateTableRequest
                                                                 {
                                                                     Database = DatabaseName,
                                                                     Table = uniqueTableName,
                                                                     Comment = "what is this",
                                                                     Location = "/testtable",
                                                                     Columns = new List<Column>
                                                                                   {
                                                                                       new Column
                                                                                           {
                                                                                               Name = "id",
                                                                                                         Type = ColumnTypes.BigInt
                                                                                           }
                                                                                   }

                                                                 };

            var client = BuildHCatalogClient();

            // act
            var task = client.CreateTable(createTableRequest);
            task.Wait();

            // assert
            Assert.IsTrue(task.Result);

            var getTablesTask = client.GetTables(DatabaseName);
            getTablesTask.Wait();

            Assert.IsTrue(getTablesTask.Result.Tables.Contains(uniqueTableName));
        }
Ejemplo n.º 3
0
        public void CreatesTableWithSixColumns()
        {
            // arrange
            this.CreateDatabaseIfNotExists();
            var uniqueTableName = BuildUniqueName();

            var createTableRequest = new CreateTableRequest
            {
                Database = DatabaseName,
                Table = uniqueTableName,
                Comment = "what is this",
                Location = "/testtable",
                Format = new TableFormatRequest
                                     {
                                         RowFormat = new RowFormatRequest
                                                                     {
                                                                         FieldsTerminatedBy = ","
                                                                     },
                                         StoredAs = TableFormats.TextFile
                                     },
                Columns = new List<Column>
                                                                                   {
                                                                                       new Column
                                                                                           {
                                                                                               Name = "a",
                                                                                                         Type = ColumnTypes.String
                                                                                           },
                                                                                                    new Column
                                                                                           {
                                                                                               Name = "b",
                                                                                                         Type = ColumnTypes.String
                                                                                           },
                                                                                                     new Column
                                                                                           {
                                                                                               Name = "c",
                                                                                                         Type = ColumnTypes.String
                                                                                           },
                                                                                                     new Column
                                                                                           {
                                                                                               Name = "d",
                                                                                                         Type = ColumnTypes.String
                                                                                           },
                                                                                                     new Column
                                                                                           {
                                                                                               Name = "e",
                                                                                                         Type = ColumnTypes.String
                                                                                           },
                                                                                                     new Column
                                                                                           {
                                                                                               Name = "f",
                                                                                                         Type = ColumnTypes.String
                                                                                           }
                                                                                   }

            };

            var client = BuildHCatalogClient();

            // act
            var task = client.CreateTable(createTableRequest);
            task.Wait();

            // assert
            Assert.IsTrue(task.Result);

            var getTablesTask = client.GetTables(DatabaseName);
            getTablesTask.Wait();

            Assert.IsTrue(getTablesTask.Result.Tables.Contains(uniqueTableName));
        }