public void InsertRow_BadData_IgnoreUnknownAndBadRows_Throws() { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "year", 2019 } }, new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } } }; var options = new InsertOptions { AllowUnknownFields = true, SkipInvalidRows = true, SuppressInsertErrors = false }; var exception = Assert.Throws <GoogleApiException>(() => table.InsertRows(rows, options)); Assert.Equal(1, exception.Error.Errors.Count); Assert.Contains("Row 2", exception.Error.Errors[0].Message); }
public void InsertRows_AllowEmptyInsertIds() { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); var table = dataset.GetTable(_fixture.HighScoreTableId); var options = new InsertOptions { AllowEmptyInsertIds = true }; var rows = new[] { BuildRow("Helen", 125, new DateTime(2012, 5, 22, 1, 20, 30, DateTimeKind.Utc)), BuildRow("Henry", 90, new DateTime(2011, 10, 12, 0, 0, 0, DateTimeKind.Utc)) }; _fixture.InsertAndWait(table, () => table.InsertRows(rows, options), 2); Assert.Null(rows[0].InsertId); Assert.Null(rows[1].InsertId); var rowsAfter = table.ListRows().ToList(); Assert.Contains(rowsAfter, r => (string)r["player"] == "Helen"); Assert.Contains(rowsAfter, r => (string)r["player"] == "Henry"); }
int MaxObjectsPerBatch <TObject>(TObjectName tableName, TObject sampleObject, InsertOptions options) where TObject : class { var metadata = DataSource.DatabaseMetadata; var table = metadata.GetTableOrView(tableName); var sqlBuilder = table.CreateSqlBuilder(false); sqlBuilder.ApplyDesiredColumns(Materializer.NoColumns); sqlBuilder.ApplyArgumentValue(DataSource, sampleObject, options); sqlBuilder.GetInsertColumns(options.HasFlag(InsertOptions.IdentityInsert)).Count(); //Call .Count() to trigger needed side-effects var parametersPerRow = DataSource.GetParameters(sqlBuilder).Count; var maxParams = metadata.MaxParameters; if (maxParams == null) { return(int.MaxValue); } var maxRows = maxParams.Value / parametersPerRow; if (metadata.MaxRowsPerValuesClause.HasValue) { maxRows = Math.Min(metadata.MaxRowsPerValuesClause.Value, maxRows); } return(maxRows); }
public void InsertRow_BadData_IgnoreUnknownAndBadRows_Silent() { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "year", 2019 } }, new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } }, }; var options = new InsertOptions { AllowUnknownFields = true, SkipInvalidRows = true, SuppressInsertErrors = true }; // Now two rows are inserted, we are ignoring unknown fields so only the last row is bad. _fixture.InsertAndWait(table, () => table.InsertRows(rows, options), 2); }
public void InsertRow_BadData_IgnoreUnknownAndBadRows_Silent() { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "year", 2019 } }, new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } }, }; var options = new InsertOptions { AllowUnknownFields = true, SkipInvalidRows = true, SuppressInsertErrors = true }; // Now two rows are inserted, we are ignoring unknown fields so only the last row is bad. var insertResult = _fixture.InsertAndWait(table, () => table.InsertRows(rows, options), 2); Assert.Equal(1, insertResult.OriginalRowsWithErrors); Assert.Equal(3, insertResult.InsertAttemptRowCount); Assert.Equal(BigQueryInsertStatus.SomeRowsInserted, insertResult.Status); Assert.Contains(insertResult.Errors, e => e.OriginalRowIndex == 2); }
public SqlServerInsertBatchTable(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, DbDataReader dataReader, SqlServerObjectName tableTypeName, InsertOptions options) : base(dataSource) { m_Source = dataReader; m_Options = options; m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); m_TableType = dataSource.DatabaseMetadata.GetUserDefinedTableType(tableTypeName); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Creating a file stream containing the Excel file to be opened FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); // Instantiating a Workbook object // Opening the Excel file through the file stream Workbook workbook = new Workbook(fstream); // Accessing the first worksheet in the Excel file Worksheet worksheet = workbook.Worksheets[0]; // Setting Formatting options InsertOptions insertOptions = new InsertOptions(); insertOptions.CopyFormatType = CopyFormatType.SameAsAbove; // Inserting a row into the worksheet at 3rd position worksheet.Cells.InsertRows(2, 1, insertOptions); // Saving the modified Excel file workbook.Save(dataDir + "InsertingARowWithFormatting.out.xls"); // Closing the file stream to free all resources fstream.Close(); // ExEnd:1 }
public void InsertRow_BadData_Silent(InsertOptions options, int[] errorRowsIndexes) { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } } }; var insertResult = table.InsertRows(rows, options); Assert.Equal(errorRowsIndexes.Length, insertResult.OriginalRowsWithErrors); Assert.Equal(errorRowsIndexes, insertResult.Errors. Select(e => (int?)e.OriginalRowIndex ?? -1). OrderBy(index => index). ToArray()); }
public void InsertRow_BadData_Throws(InsertOptions options, int[] errorRowsIndexes) { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } } }; var exception = Assert.Throws <GoogleApiException>(() => table.InsertRows(rows, options)); Assert.Equal(errorRowsIndexes.Length, exception.Error.Errors.Count); foreach (var index in errorRowsIndexes) { Assert.Contains(exception.Error.Errors, e => e.Message.ToLower().Contains($"in row {index}")); } }
public async Task Test_Query_Update_PreserveExpiry() { await _fixture.BuildAsync(); var docId = System.Guid.NewGuid().ToString(); var doc = new { id = docId, testName = nameof(Test_Query_Update_PreserveExpiry), content = "initial" }; var collection = await _fixture.GetDefaultCollection(); var opts = new InsertOptions().Expiry(TimeSpan.FromSeconds(30)); await collection.InsertAsync(docId, doc, options : opts); try { var result = await _fixture.Cluster.QueryAsync <dynamic>("UPDATE default AS d SET d.content = 'updated' WHERE d.id = $1", opts => opts.Parameter(docId) .PreserveExpiry(true)); // for server version >= 7.1.0, we expect it to succeed. Assert.Empty(result.Errors); Assert.Equal <uint?>(1, result.MetaData?.Metrics?.MutationCount); } catch (CouchbaseException ex) { // for < 7.1.0, we expect an appropriate error. Assert.Contains("Unrecognized parameter in request: preserve_expiry", ex.Message);; } }
public long Put(byte[] key, string val, InsertOptions flag, Transaction txn) { if (key == null || val == null) { throw new Exception("key or/and val can't be null"); } return(BangDBNative.Put_Tran(_connection, key, key.Length, val, val.Length, (int)flag, txn.GetTranPtr())); }
public long Put(string key, byte[] val, InsertOptions flag) { if (key == null || val == null) { throw new Exception("key or/and val can't be null"); } return(BangDBNative.Put(_connection, key, key.Length, val, val.Length, (int)flag)); }
public void Insert <TDocument>(TDocument instance, InsertOptions options = null) where TDocument : class { var command = builder.PrepareInsert(new[] { instance }, options); configuration.Hooks.BeforeInsert(instance, command.Mapping, this); ExecuteNonQuery(command); configuration.Hooks.AfterInsert(instance, command.Mapping, this); configuration.RelatedDocumentStore.PopulateRelatedDocuments(this, instance); }
public async Task InsertAsync <TDocument>(TDocument instance, InsertOptions options, CancellationToken cancellationToken = default) where TDocument : class { var command = builder.PrepareInsert(new[] { instance }, options); await configuration.Hooks.BeforeInsertAsync(instance, command.Mapping, this); await ExecuteNonQueryAsync(command, cancellationToken); await configuration.Hooks.AfterInsertAsync(instance, command.Mapping, this); configuration.RelatedDocumentStore.PopulateRelatedDocuments(this, instance); }
public SqlServerInsertBatch(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, DbDataReader dataReader, SqlServerObjectName tableTypeName, InsertOptions options) : base(dataSource) { m_Source = dataReader; m_Options = options; m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); m_TableType = dataSource.DatabaseMetadata.GetUserDefinedType(tableTypeName); if (!m_TableType.IsTableType) { throw new MappingException($"{m_TableType.Name} is not a user defined table type"); } }
public void ModifyRequest() { var options = new InsertOptions { AllowUnknownFields = true }; TableDataInsertAllRequest request = new TableDataInsertAllRequest(); options.ModifyRequest(request); Assert.Equal(true, request.IgnoreUnknownValues); }
public void InsertRow_BadTable() { var client = BigQueryClient.Create(_fixture.ProjectId); var options = new InsertOptions { AllowUnknownFields = true, SkipInvalidRows = true, SuppressInsertErrors = true }; var row = new BigQueryInsertRow { { "noSuchField", 10 } }; // This should still throw because the error is not on inserting a specific row. var exception = Assert.Throws <GoogleApiException>(() => client.InsertRow(_fixture.DatasetId, "noSuchTable", row)); }
public PreparedCommand PrepareInsert(IReadOnlyList <object> documents, InsertOptions options = null) { options ??= InsertOptions.Default; var mapping = GetMapping(documents); var sb = new StringBuilder(); AppendInsertStatement(sb, mapping, options.TableName, options.SchemaName, options.Hint, documents.Count, options.IncludeDefaultModelColumns); var parameters = GetDocumentParameters(m => keyAllocator(m), options.CustomAssignedId, documents, mapping); AppendRelatedDocumentStatementsForInsert(sb, parameters, mapping, documents); return(new PreparedCommand(sb.ToString(), parameters, RetriableOperation.Insert, mapping, options.CommandTimeout)); }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedTab.Text == "Insert Image") { this.retrievedImageList.MultiSelect = false; this.insertOption = InsertOptions.Image; } else { this.retrievedImageList.MultiSelect = true; this.insertOption = InsertOptions.Gallery; } }
private void DrawInsert() { insertOption = (InsertOptions)EditorGUILayout.EnumPopup("Insert On", insertOption); if (insertOption == InsertOptions.custom) { insertIndex = EditorGUILayout.IntField("Start Index", insertIndex); if (insertIndex < 0) { insertIndex = 0; } } stringToInsert = EditorGUILayout.TextField("Insert:", stringToInsert); }
public void ModifyRequest() { var options = new InsertOptions { AllowUnknownFields = true, SkipInvalidRows = true, TemplateSuffix = "fromTemplate" }; TableDataInsertAllRequest request = new TableDataInsertAllRequest(); options.ModifyRequest(request); Assert.Equal(true, request.IgnoreUnknownValues); Assert.Equal(true, request.SkipInvalidRows); Assert.Equal("fromTemplate", request.TemplateSuffix); }
public static InsertOptions Defaults(this InsertOptions opts, DurabilityLevel?durability, TimeSpan?timeout) { opts = new InsertOptions().RetryStrategy(RetryStrategy); if (durability.HasValue) { opts = opts.Durability(durability.Value); } if (timeout.HasValue) { opts = opts.Timeout(timeout.Value); } return(opts); }
public PostgreSqlInsertBatch(PostgreSqlDataSourceBase dataSource, PostgreSqlObjectName tableName, IEnumerable <TObject> objects, InsertOptions options) : base(dataSource) { if (dataSource == null) { throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null."); } var sourceList = objects.AsReadOnlyList(); if (sourceList == null || sourceList.Count == 0) { throw new ArgumentException($"{nameof(objects)} is null or empty.", nameof(objects)); } m_SourceList = sourceList; m_Options = options; m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName); }
public void InsertEquivalents_ParamsRows() { var datasetId = "dataset"; var tableId = "table"; var reference = new TableReference { ProjectId = ProjectId, DatasetId = datasetId, TableId = tableId }; var schema = new TableSchemaBuilder().Build(); var options = new InsertOptions(); var stream = new MemoryStream(); var rows = new[] { new BigQueryInsertRow(), new BigQueryInsertRow() }; VerifyEquivalent( client => client.Insert(MatchesWhenSerialized(reference), rows, null), client => client.Insert(datasetId, tableId, rows[0], rows[1]), client => client.Insert(ProjectId, datasetId, tableId, rows[0], rows[1]), client => new BigQueryTable(client, GetTable(reference)).Insert(rows[0], rows[1])); }
public long Put(byte[] key, ref DataVar dv, InsertOptions flag, Transaction txn) { if (key == null) { throw new Exception("key can't be null"); } IntPtr pBuf = dv.bufferPointer; int buflen = dv.bufferLength; int dlen = dv.dataLength; int dofft = dv.dataOffset; int eflag = (int)dv.opsFlag; long retval = BangDBNative.PutAdvanced_Tran(_connection, key, key.Length, pBuf, buflen, ref dlen, dofft, ref eflag, (int)flag, txn.GetTranPtr()); dv.dataLength = dlen; dv.opsFlag = (BangDBDataOpsFlag)eflag; return(retval); }
public void InsertAsyncEquivalents_RowCollection() { var datasetId = "dataset"; var tableId = "table"; var reference = new TableReference { ProjectId = ProjectId, DatasetId = datasetId, TableId = tableId }; var schema = new TableSchemaBuilder().Build(); var options = new InsertOptions(); var token = new CancellationTokenSource().Token; var stream = new MemoryStream(); var rows = new[] { new BigQueryInsertRow(), new BigQueryInsertRow() }; VerifyEquivalentAsync( client => client.InsertAsync(MatchesWhenSerialized(reference), rows, options, token), client => client.InsertAsync(datasetId, tableId, rows, options, token), client => client.InsertAsync(ProjectId, datasetId, tableId, rows, options, token), client => new BigQueryTable(client, GetTable(reference)).InsertAsync(rows, options, token)); }
/// <summary> /// The OK function of the modal dialog resulting in letting the ContentSource know the action is complete. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonInsert_Click(object sender, EventArgs e) { if (retrievedImageList.SelectedIndices.Count == 0) { MessageBox.Show("No images selected. Please choose at least one image or cancel to continue.", "No image selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (tabControl1.SelectedTab.Text == "Insert Image") { this.insertOption = InsertOptions.Image; } else { this.insertOption = InsertOptions.Gallery; } base.DialogResult = DialogResult.OK; } }
public void InsertRow_BadData_IgnoreBadData() { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "name", BigQueryDbType.String } }.Build()); var row = new BigQueryInsertRow { { "noSuchField", 10 } }; var options = new InsertOptions { AllowUnknownFields = true }; _fixture.InsertAndWait(table, () => table.InsertRow(row, options), 1); }
public async Task <(ulong updatedCas, MutationToken?mutationToken)> UnstageInsertOrReplace(ICouchbaseCollection collection, string docId, ulong cas, object finalDoc, bool insertMode) { if (insertMode) { var opts = new InsertOptions().Defaults(_durability, _keyValueTimeout); var mutateResult = await collection.InsertAsync(docId, finalDoc, opts).CAF(); return(mutateResult.Cas, mutateResult?.MutationToken); } else { var opts = GetMutateInOptions(StoreSemantics.Replace).Cas(cas); var mutateResult = await collection.MutateInAsync(docId, specs => specs.Upsert(TransactionFields.TransactionInterfacePrefixOnly, string.Empty, isXattr : true, createPath : true) .Remove(TransactionFields.TransactionInterfacePrefixOnly, isXattr : true) .SetDoc(finalDoc), opts).CAF(); return(mutateResult.Cas, mutateResult?.MutationToken); } }
public void InsertRow_BadData_Silent(InsertOptions options) { var client = BigQueryClient.Create(_fixture.ProjectId); var dataset = client.GetDataset(_fixture.DatasetId); // Don't insert into a table used by other tests... var table = dataset.CreateTable( _fixture.CreateTableId(), new TableSchemaBuilder { { "year", BigQueryDbType.Int64 } }.Build()); var rows = new BigQueryInsertRow[] { new BigQueryInsertRow { { "noSuchField", 10 } }, new BigQueryInsertRow { { "year", "Unknown" } } }; table.InsertRows(rows, options); }