Comments (6)
Using instanceof operator? instanceof operator is used to find whether the object is an instance of the specified type. Therefore, you can check whether the value is an instance of int type. If so, you can store the value into an int variable. For example: if ( obj instanceof int ) { int myObject = obj; }
But I have to check all columns in a row and it takes lot of operation.
from java-spanner.
Hey @nitinsridar I am curious to hear more about what your use case is here. Mutations are usually for modifying Spanner rows. So usually you would be putting data into them, and if so would have the Java type information. For any given key I would suspect you would know the type to cast it to, correct me if I am wrong though.
from java-spanner.
When mutation is gone through the transaction we are publishing the mutation to pub/sub as json format, this is the use case, it's difficult to consume the mutation object at the other end so we are converting to json object and publishing to pub/sub and here I cannot convert to proper data type. Please help on this...
from java-spanner.
There's no standard method in the Java client library that does this, as Mutation
objects are primarily intended for sending mutations to the backend, and not for reading out or sending to other services. The best way to do what you want, would be to add a method like this to your own code, and use that to read the actual underlying value from a mutation:
Object getUnderlyingValue(Value v) {
switch(v.getType().getCode()) {
case ARRAY:
switch(v.getType().getArrayElementType().getCode()) {
case BOOL:
return v.getBoolArray();
case BYTES:
return v.getBytesArray();
case DATE:
return v.getDateArray();
case FLOAT64:
return v.getFloat64Array();
case INT64:
return v.getInt64Array();
case STRING:
return v.getStringArray();
case TIMESTAMP:
return v.getTimestampArray();
case STRUCT:
// Array of struct is not supported.
case ARRAY:
// Array of array is not supported.
default:
break;
}
break;
case BOOL:
return v.getBool();
case BYTES:
return v.getBytes();
case DATE:
return v.getDate();
case FLOAT64:
return v.getFloat64();
case INT64:
return v.getInt64();
case STRING:
return v.getString();
case STRUCT:
return v.getStruct();
case TIMESTAMP:
return v.getTimestamp();
default:
break;
}
throw new IllegalStateException("Value with unknown type: " + v.toString());
}
from java-spanner.
@nitinsridar Could you indicate whether the above example solves this for you? I don't think this is a very common use case, so it's not something that I think we want to add to the client library. If you add the above code snippet to your own code base, you should however be able to achieve what you wanted.
from java-spanner.
Closing this as we have not heard back in a while. Please re-open if additional information is needed.
from java-spanner.
Related Issues (20)
- Library Compatibility with Protobuf-Java 4.26.x+
- spanner.DatabaseClientImplTest: testSessionPoolExhaustedError_containsStackTraces failed HOT 3
- ITEmulatorConcurrentTransactionsTest is flaky with multiplexed sessions HOT 1
- ITReadOnlyTxnTest is flaky with multiplexed sessions
- OpenTelemetry traces show a missing SpanID HOT 1
- OpenTelemetrySpanTest.transactionRunner is flaky with multiplexed sessions
- Fix RESOURCE_EXHAUSTED admin quota limit exceed failures in test pipelines.
- Flaky failure in com.google.cloud.spanner.it.ITDmlReturningTest.dmlReturningWithExecuteQuery[Dialect = POSTGRESQL]
- Flaky test failure in AsyncTransactionManagerTest.asyncTransactionManagerWaitsUntilAsyncUpdateHasFinished with MultiplexedSessions=true
- Flaky failure in ITDmlReturningTest.dmlReturningWithExecuteQuery[Dialect = GOOGLE_STANDARD_SQL]
- spanner.it.slow.ITBackupTest: test02_RetryNonIdempotentRpcsReturningLongRunningOperations failed HOT 1
- spanner.it.slow.ITBackupTest: test03_Delete failed HOT 1
- spanner.SessionPoolOptionsTest: testToBuilder[min sessions = 500, max sessions = 600] failed HOT 1
- spanner.BatchCreateSessionsTest: testSpannerReturnsAllAvailableSessionsAndThenNoSessions failed HOT 1
- spanner.connection.SavepointMockServerTest: testKeepAlive[dialect = GOOGLE_STANDARD_SQL, useVirtualThreads = true] failed HOT 2
- spanner.connection.SavepointMockServerTest: testKeepAlive[dialect = GOOGLE_STANDARD_SQL, useVirtualThreads = false] failed HOT 2
- spanner.connection.SavepointMockServerTest: testKeepAlive[dialect = POSTGRESQL, useVirtualThreads = false] failed HOT 2
- SavepointMockServerTest is flaky
- spanner.SessionPoolOptionsTest: testToBuilder[min sessions = 600, max sessions = 500] failed HOT 1
- BatchCreateSessionsTest is flaky
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-spanner.