Codota Logo
Struct
Code IndexAdd Codota to your IDE (free)

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

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

Refine searchRefine arrow

  • BooleanSubject
  • Truth
  • ValueBinder
  • Type
  • Mutation.WriteBuilder
  • Statement
  • ITQueryTest
  • Common ways to obtain Struct
private void myMethod () {
Struct s =
  • Codota IconResultSet resultSet;resultSet.getCurrentRowAsStruct()
  • Smart code suggestions by Codota
}
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 Value getValue(int fieldIndex) {
 Type fieldType = value.getColumnType(fieldIndex);
 switch (fieldType.getCode()) {
  case BOOL:
   return Value.bool(value.getBoolean(fieldIndex));
  case INT64:
   return Value.int64(value.getLong(fieldIndex));
  case STRING:
   return Value.string(value.getString(fieldIndex));
  case BYTES:
   return Value.bytes(value.getBytes(fieldIndex));
  case FLOAT64:
   return Value.float64(value.getDouble(fieldIndex));
  case DATE:
   return Value.date(value.getDate(fieldIndex));
  case TIMESTAMP:
   return Value.timestamp(value.getTimestamp(fieldIndex));
  case STRUCT:
   return Value.struct(value.getStruct(fieldIndex));
  case ARRAY:
    Type elementType = fieldType.getArrayElementType();
    switch (elementType.getCode()) {
     case BOOL:
      return Value.boolArray(value.getBooleanArray(fieldIndex));
     case INT64:
      return Value.int64Array(value.getLongArray(fieldIndex));
     case STRING:
      return Value.stringArray(value.getStringList(fieldIndex));
     case BYTES:
origin: googleapis/google-cloud-java

@Test
public void bindBoolArrayEmpty() {
 Struct row =
   execute(
     Statement.newBuilder("SELECT @v").bind("v").toBoolArray(Arrays.<Boolean>asList()),
     Type.array(Type.bool()));
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getBooleanList(0)).containsExactly();
}
origin: googleapis/google-cloud-java

@Override
public int hashCode() {
 int result = getType().hashCode();
 for (int i = 0; i < getColumnCount(); ++i) {
  result = 31 * result + Objects.hashCode(getAsObject(i));
 }
 return result;
}
origin: googleapis/google-cloud-java

private void checkNonNullStruct(int columnIndex, Object columnNameForError) {
 Type actualType = getColumnType(columnIndex);
 checkState(
   actualType.getCode() == Code.STRUCT,
   "Column %s is not of correct type: expected STRUCT<...> but was %s",
   columnNameForError,
   actualType);
 checkNonNull(columnIndex, columnNameForError);
}
origin: googleapis/google-cloud-java

private Object getAsObject(int columnIndex) {
 Type type = getColumnType(columnIndex);
 if (isNull(columnIndex)) {
  return null;
 switch (type.getCode()) {
  case BOOL:
   return getBooleanInternal(columnIndex);
  case INT64:
   return getLongInternal(columnIndex);
  case FLOAT64:
   return getDoubleInternal(columnIndex);
  case STRING:
   return getStringInternal(columnIndex);
  case BYTES:
   return getBytesInternal(columnIndex);
  case TIMESTAMP:
   return getTimestampInternal(columnIndex);
  case DATE:
   return getDateInternal(columnIndex);
  case STRUCT:
   return getStructInternal(columnIndex);
  case ARRAY:
   switch (type.getArrayElementType().getCode()) {
    case BOOL:
     return getBooleanListInternal(columnIndex);
    case INT64:
     return getLongListInternal(columnIndex);
    case FLOAT64:
     return getDoubleListInternal(columnIndex);
origin: googleapis/google-cloud-java

@Test
public void writeTimestampNull() {
 write(baseInsert().set("TimestampValue").to((Timestamp) null).build());
 Struct row = readLastRow("TimestampValue");
 assertThat(row.isNull(0)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void writeBoolArray() {
 write(baseInsert().set("BoolArrayValue").toBoolArray(Arrays.asList(true, null, false)).build());
 Struct row = readLastRow("BoolArrayValue");
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getBooleanList(0)).containsExactly(true, null, false).inOrder();
 expectedException.expect(NullPointerException.class);
 row.getBooleanArray(0);
}
origin: googleapis/google-cloud-java

@Test
public void structArrayFieldNull() {
 Type elementType =
   Type.struct(
     Arrays.asList(
       Type.StructField.of("ff1", Type.string()),
       Type.StructField.of("ff2", Type.int64())));
 Struct struct =
   Struct.newBuilder().set("f1").to("x").set("f2").toStructArray(elementType, null).build();
 assertThat(struct.getType())
   .isEqualTo(
     Type.struct(
       Type.StructField.of("f1", Type.string()),
       Type.StructField.of("f2", Type.array(elementType))));
 assertThat(struct.isNull(0)).isFalse();
 assertThat(struct.isNull(1)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void bindStructNull() {
 Struct row =
   execute(
     Statement.newBuilder("SELECT @p IS NULL")
       .bind("p")
       .to(
         Type.struct(
           asList(
             Type.StructField.of("f1", Type.string()),
             Type.StructField.of("f2", Type.float64()))),
         null)
       .build(),
     Type.bool());
 assertThat(row.getBoolean(0)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void simpleInsert() {
 TransactionManager manager = client.transactionManager();
 TransactionContext txn = manager.begin();
 assertThat(manager.getState()).isEqualTo(TransactionState.STARTED);
 txn.buffer(
   Mutation.newInsertBuilder("T").set("K").to("Key1").set("BoolValue").to(true).build());
 manager.commit();
 assertThat(manager.getState()).isEqualTo(TransactionState.COMMITTED);
 Struct row = client.singleUse().readRow("T", Key.of("Key1"), Arrays.asList("K", "BoolValue"));
 assertThat(row.getString(0)).isEqualTo("Key1");
 assertThat(row.getBoolean(1)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void writeBool() {
 write(baseInsert().set("BoolValue").to(true).build());
 Struct row = readLastRow("BoolValue");
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getBoolean(0)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void bindInt64ArrayEmpty() {
 Struct row =
   execute(
     Statement.newBuilder("SELECT @v").bind("v").toInt64Array(Arrays.<Long>asList()),
     Type.array(Type.int64()));
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getLongList(0)).containsExactly();
}
origin: googleapis/google-cloud-java

@Test
public void bindTimestampArrayEmpty() {
 Struct row =
   execute(
     Statement.newBuilder("SELECT @v")
       .bind("v")
       .toTimestampArray(Arrays.<Timestamp>asList()),
     Type.array(Type.timestamp()));
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getTimestampList(0)).containsExactly();
}
origin: googleapis/google-cloud-java

@Test
public void writeString() {
 write(baseInsert().set("StringValue").to("V1").build());
 Struct row = readLastRow("StringValue");
 assertThat(row.isNull(0)).isFalse();
 assertThat(row.getString(0)).isEqualTo("V1");
}
origin: googleapis/google-cloud-java

@Test
public void singleStrong() {
 History expected = history.get(history.size() - 1);
 ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction();
 Struct row = readRow(readContext);
 assertThat(row).isNotNull();
 assertThat(row.getString(0)).isEqualTo(expected.value);
 assertThat(readContext.getReadTimestamp()).isAtLeast(expected.timestamp);
 row = readRow(client.singleUse());
 assertThat(row).isNotNull();
 assertThat(row.getString(0)).isEqualTo(expected.value);
}
origin: googleapis/google-cloud-java

@Test
public void bindStructWithStructField() {
 Struct nestedStruct = Struct.newBuilder().set("ff1").to("abc").build();
 Struct p = Struct.newBuilder().set("f1").to(nestedStruct).build();
 Struct row =
   executeWithRowResultType(
     Statement.newBuilder("SELECT @p.f1.ff1").bind("p").to(p).build(),
     nestedStruct.getType());
 assertThat(row.getString(0)).isEqualTo("abc");
}
origin: googleapis/google-cloud-java

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

@Test
public void bindStructWithNullStructField() {
 Type emptyStructType = Type.struct(new ArrayList<StructField>());
 Struct p = Struct.newBuilder().set("f1").to(emptyStructType, null).build();
 Struct row =
   execute(Statement.newBuilder("SELECT @p.f1 IS NULL").bind("p").to(p).build(), Type.bool());
 assertThat(row.getBoolean(0)).isTrue();
}
origin: googleapis/google-cloud-java

@Test
public void bindDateArrayNull() {
 Struct row =
   execute(
     Statement.newBuilder("SELECT @v").bind("v").toDateArray(null), Type.array(Type.date()));
 assertThat(row.isNull(0)).isTrue();
}
com.google.cloud.spannerStruct

Javadoc

Represents a non- NULL value of Type.Code#STRUCT. Such values are a tuple of named and typed columns, where individual columns may be null. Individual rows from a read or query operation can be considered as structs; ResultSet#getCurrentRowAsStruct() allows an immutable struct to be created from the row that the result set is currently positioned over.

Struct instances are immutable.

This class does not support representing typed NULL Struct values.

However, struct values inside SQL queries are always typed and can be externally supplied to a query only in the form of struct/array-of-struct query parameter values for which typed NULL struct values can be specified in the following ways:

1. As a standalone NULL struct value or as a nested struct field value, constructed using ValueBinder#to(Type,Struct) or Value#struct(Type,Struct).

2. As as a null Struct reference representing a NULL struct typed element value inside an array/list of ' Struct' references, that is used to construct an array-of-struct value using Value#structArray(Type,Iterable) or ValueBinder#toStructArray(Type,Iterable). In this case, the type of the NULL struct value is assumed to be the same as the explicitly specified struct element type of the array/list.

Most used methods

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

Popular in Java

  • Parsing JSON documents to java classes using gson
  • addToBackStack (FragmentTransaction)
  • getSharedPreferences (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now