congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Struct.getLong
Code IndexAdd Tabnine to your IDE (free)

How to use
getLong
method
in
com.google.cloud.spanner.Struct

Best Java code snippets using com.google.cloud.spanner.Struct.getLong (Showing top 20 results out of 315)

origin: googleapis/google-cloud-java

@Override
public long getLong(String columnName) {
 return getCurrentRowAsStruct().getLong(columnName);
}
origin: googleapis/google-cloud-java

 return Value.bool(value.getBoolean(fieldIndex));
case INT64:
 return Value.int64(value.getLong(fieldIndex));
case STRING:
 return Value.string(value.getString(fieldIndex));
origin: googleapis/google-cloud-java

@Override
public long getLong(int columnIndex) {
 return getCurrentRowAsStruct().getLong(columnIndex);
}
origin: googleapis/google-cloud-java

 @Override
 public Void run(TransactionContext transaction) {
  long rowCount =
    transaction.executeUpdate(Statement.of("UPDATE T SET v = v * 2 WHERE k = 'boo2';"));
  assertThat(rowCount).isEqualTo(1);
  assertThat(transaction.readRow("T", Key.of("boo2"), Arrays.asList("v")).getLong(0))
    .isEqualTo(2 * 2);
  return null;
 }
};
origin: googleapis/google-cloud-java

@Test
public void simple() {
 Struct row = execute(Statement.of("SELECT 1"), Type.int64());
 assertThat(row.getLong(0)).isEqualTo(1);
}
origin: googleapis/google-cloud-java

@Ignore // Not yet supported by the backend.
@Test
public void arrayOfStructNullElement() {
 Type structType =
   Type.struct(StructField.of("", Type.string()), StructField.of("", Type.int64()));
 Struct row =
   execute(
     Statement.of(
       "SELECT ARRAY(SELECT AS STRUCT 'a', 1"
         + " UNION ALL SELECT CAST (NULL AS STRUCT<string,int64>))"),
     Type.array(structType));
 assertThat(row.isNull(0)).isFalse();
 List<Struct> value = row.getStructList(0);
 assertThat(value.size()).isEqualTo(2);
 assertThat(value.get(0).getType()).isEqualTo(structType);
 assertThat(value.get(0).getString(0)).isEqualTo("a");
 assertThat(value.get(0).getLong(1)).isEqualTo(1);
 assertThat(value.get(1)).isNull();
}
origin: googleapis/google-cloud-java

@Test
public void bindInt64() {
 Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(1234), Type.int64());
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getLong(0)).isEqualTo(1234);
}
origin: googleapis/google-cloud-java

@Test
public void unnamedFields() {
 Struct struct = Struct.newBuilder().add(Value.int64(2)).add(Value.int64(3)).build();
 assertThat(struct.getType())
   .isEqualTo(
     Type.struct(
       Type.StructField.of("", Type.int64()), Type.StructField.of("", Type.int64())));
 assertThat(struct.getLong(0)).isEqualTo(2);
 assertThat(struct.getLong(1)).isEqualTo(3);
}
origin: googleapis/google-cloud-java

@Test
public void bindStructWithUnnamedFields() {
 Struct p = Struct.newBuilder().add(Value.int64(1337)).add(Value.int64(7331)).build();
 Struct row =
   executeWithRowResultType(
     Statement.newBuilder("SELECT * FROM UNNEST([@p])").bind("p").to(p).build(),
     p.getType());
 assertThat(row.getLong(0)).isEqualTo(1337);
 assertThat(row.getLong(1)).isEqualTo(7331);
}
origin: googleapis/google-cloud-java

@Test
public void writeInt64() {
 write(baseInsert().set("Int64Value").to(1234).build());
 Struct row = readLastRow("Int64Value");
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getLong(0)).isEqualTo(1234L);
}
origin: googleapis/google-cloud-java

    .singleUse(TimestampBound.strong())
    .readRow("T", Key.of(key), Arrays.asList("V"))
    .getLong(0))
.isEqualTo(Long.valueOf(numThreads));
origin: googleapis/google-cloud-java

@Test
public void standardDMLWithDuplicates() {
 executeUpdate(DML_COUNT, INSERT_DML);
 executeUpdate(
   4,
   "UPDATE T SET v = 200 WHERE k = 'boo1';",
   "UPDATE T SET v = 300 WHERE k = 'boo1';",
   "UPDATE T SET v = 400 WHERE k = 'boo1';",
   "UPDATE T SET v = 500 WHERE k = 'boo1';");
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(500);
 executeUpdate(DML_COUNT, DELETE_DML, DELETE_DML);
}
origin: googleapis/google-cloud-java

@Test
public void standardDML() {
 executeUpdate(DML_COUNT, INSERT_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(1);
 executeUpdate(DML_COUNT, UPDATE_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(100);
 executeUpdate(DML_COUNT, DELETE_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V")))
   .isNull();
}
origin: googleapis/google-cloud-java

 @Override
 public Long run(TransactionContext transaction) throws SpannerException {
  Struct row = strategy.read(transaction, key);
  long newValue = row.getLong(0) + 1;
  transaction.buffer(
    Mutation.newUpdateBuilder("T").set("K").to(key).set("V").to(newValue).build());
  commitBarrier.countDown();
  // Synchronize so that all threads attempt to commit at the same time.
  Uninterruptibles.awaitUninterruptibly(commitBarrier);
  return newValue;
 }
};
origin: googleapis/google-cloud-java

@Test
public void partitionedDML() {
 executeUpdate(DML_COUNT, INSERT_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(1);
 long rowCount = client.executePartitionedUpdate(Statement.of(UPDATE_DML));
 // Note: With PDML there is a possibility of network replay or partial update to occur, causing
 // this assert to fail. We should remove this assert if it is a recurring failure in IT tests.
 assertThat(rowCount).isEqualTo(DML_COUNT);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(100);
 rowCount = client.executePartitionedUpdate(Statement.of(DELETE_DML));
 assertThat(rowCount).isEqualTo(DML_COUNT);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V")))
   .isNull();
}
origin: googleapis/google-cloud-java

@Test
public void duplicateFields() {
 // Duplicate fields are allowed - some SQL queries produce this type of value.
 Struct struct = Struct.newBuilder().set("").to("x").set("").to(Value.int64(2)).build();
 assertThat(struct.getType())
   .isEqualTo(
     Type.struct(
       Type.StructField.of("", Type.string()), Type.StructField.of("", Type.int64())));
 assertThat(struct.isNull(0)).isFalse();
 assertThat(struct.isNull(1)).isFalse();
 assertThat(struct.getString(0)).isEqualTo("x");
 assertThat(struct.getLong(1)).isEqualTo(2);
}
origin: googleapis/google-cloud-java

private void assertRow(Struct actualRow, JSONArray expectedRow) throws Exception {
 assertThat(actualRow.getColumnCount()).isEqualTo(expectedRow.length());
 for (int i = 0; i < expectedRow.length(); i++) {
  switch (actualRow.getColumnType(i).getCode()) {
   case BOOL:
    assertThat(actualRow.getBoolean(i)).isEqualTo(expectedRow.getBoolean(i));
    break;
   case STRING:
    assertThat(actualRow.getString(i)).isEqualTo(expectedRow.getString(i));
    break;
   case INT64:
    assertThat(actualRow.getLong(i)).isEqualTo(expectedRow.getLong(i));
    break;
   case FLOAT64:
    assertThat(actualRow.getDouble(i)).isEqualTo(expectedRow.getDouble(i));
    break;
   case BYTES:
    assertThat(actualRow.getBytes(i))
      .isEqualTo(ByteArray.fromBase64(expectedRow.getString(i)));
    break;
   case ARRAY:
    Type elementType = actualRow.getColumnType(i).getArrayElementType();
    assertArray(getRawList(actualRow, i, elementType), expectedRow.getJSONArray(i));
    break;
   default:
    Assert.fail("Unexpected type code:" + actualRow.getColumnType(i).getCode());
  }
 }
}
origin: googleapis/google-cloud-java

assertThat(value.get(0).getType()).isEqualTo(structType);
assertThat(value.get(0).getString(0)).isEqualTo("a");
assertThat(value.get(0).getLong(1)).isEqualTo(1);
assertThat(value.get(1).getType()).isEqualTo(structType);
assertThat(value.get(1).getString(0)).isEqualTo("b");
assertThat(value.get(1).getLong(1)).isEqualTo(2);
origin: googleapis/google-cloud-java

@Test
public void builder() {
 // These tests are basic: AbstractStructReaderTypesTest already covers all type getters.
 Struct struct =
   Struct.newBuilder()
     .set("f1")
     .to("x")
     .set("f2")
     .to(2)
     .set("f3")
     .to(Value.bool(null))
     .build();
 assertThat(struct.getType())
   .isEqualTo(
     Type.struct(
       Type.StructField.of("f1", Type.string()),
       Type.StructField.of("f2", Type.int64()),
       Type.StructField.of("f3", Type.bool())));
 assertThat(struct.isNull(0)).isFalse();
 assertThat(struct.isNull(1)).isFalse();
 assertThat(struct.isNull(2)).isTrue();
 assertThat(struct.getString(0)).isEqualTo("x");
 assertThat(struct.getLong(1)).isEqualTo(2);
}
origin: googleapis/google-cloud-java

@Test
public void bindStructWithDuplicateFieldNames() {
 Struct p =
   Struct.newBuilder()
     .set("f1")
     .to(Value.int64(1337))
     .set("f1")
     .to(Value.string("1337"))
     .build();
 Struct row =
   executeWithRowResultType(
     Statement.newBuilder("SELECT * FROM UNNEST([@p])").bind("p").to(p).build(),
     p.getType());
 assertThat(row.getLong(0)).isEqualTo(1337);
 assertThat(row.getString(1)).isEqualTo("1337");
}
com.google.cloud.spannerStructgetLong

Popular methods of Struct

  • getString
  • getColumnType
  • isNull
  • getBoolean
  • getBytes
  • getType
  • newBuilder
    Returns a builder for creating a non- NULL Struct instance.
  • getBooleanArray
  • getBooleanList
  • getBytesList
  • getColumnCount
  • getDate
  • getColumnCount,
  • getDate,
  • getDateList,
  • getDouble,
  • getDoubleArray,
  • getDoubleList,
  • getLongArray,
  • getLongList,
  • getStringList

Popular in Java

  • Updating database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • setScale (BigDecimal)
  • getExternalFilesDir (Context)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Path (java.nio.file)
  • BoxLayout (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now