How can I insert data into this structure in BigQuery? - google-bigquery

In BigQuery, I want to insert some data into this very simple data structure:
Field Type Mode
id STRING NULLABLE
policies RECORD REPEATED
s RECORD NULLABLE
something STRING NULLABLE
riskTypes RECORD REPEATED
code STRING NULLABLE
In the light of my previous question I would expect the syntax to be as follows:
UPDATE `tablename` SET policies = ARRAY_CONCAT(
policies, [
struct<s struct<something STRING, riskTypes ARRAY<struct<code STRING>>>
("example something", [("example description")])
]
)
WHERE id = 'Moose';
But this gives an error:
Unexpected "[" (before the "example description")

Below should work
update `tablename` set policies = policies || [
struct<s struct<something string, riskTypes array<struct<code string>> >>
(struct('example something' as something, [struct('example description 1' as code), struct('example description 2')]))
]
where id = 'Moose'

Related

error in spark_sql with "value as is not a member of object"

I have the case class like:
Hotel (id: String , name: String, cc1: String, city_preferred: String)
the csv is like:
id
name
cc1
city_hotel
1949417
apart A
pl
Sopot
2023862
apart B
es
Granada
1967734
apart C
hr
Ici
and I have to show the id, name and country but only with the hotels in Spain
I try:
val hotelsSpain = Hotel.as("Hoteles")
.select("cc1", "id", "name", "city_hotel")
.where("cc1" == "es")
display(hotelsSpain)
but the code return me
error: value as is not a member of object Hotel
val hotelsSpain = Hotel.as("Hoteles")
I think it is a little error but I don't see it. Thank you
In your schema, the column is defined as "city_prefered" (sic), but your code contains "city_hotel"
Looks to me that this error is simply telling you that "city_hotel" doesn't exist on this object

Remove String and Symbols

I am trying to create a query to remove some varchar and symbols from a big string, basically a table will have a column with this format(the information comes from an API call):
$.owner = "javier#tl.com" and $.asignee ="joe" and $.Entities.Entity = "12345" And $.CountryService.Country ="1" and $.CountryService.Service="B"
so the requirement is to take the main "column names" from the sample, so at the end the string will be like:
owner = "javier#tl.com" and asignee ="joe" and Entity = "12345" And Country ="1" and Service="B"
this should be dynamic because we could have more data like $.Entities.Name, $.CountryService.Region, etc
This is rather simple and can be done leveraging STRING_SPLIT, STRING_AGG, and CHARINDEX.
DECLARE #string VARCHAR(1000) =
'$.owner = "javier#tl.com" and $.asignee ="joe" and $.Entities.Entity = "12345" And $.CountryService.Country ="1" and $.CountryService.Service="B"';
SELECT NewString =
STRING_AGG(SUBSTRING(split.value,IIF(p.P1>0 AND p.P2>p.P1,p.P1+1,1),8000),'and ')
FROM STRING_SPLIT(REPLACE(REPLACE(#string,'$.',''),'and ','|'),'|') AS split
CROSS APPLY (VALUES(CHARINDEX('.',split.value), CHARINDEX('"',split.value))) AS p(P1,P2);
Results:
owner = "javier#tl.com" and asignee ="joe" and Entity = "12345" and Country ="1" and Service="B"

Spring Boot Autoimport import.sql file - Getting a "Column Not found" Error

So I have a table in postgresql and I want to fill it with some values on application start. Here is the Entity (in Kotlin):
#Entity
class CalculationType(
#Id #GeneratedValue(strategy = GenerationType.AUTO)
var id: Long = 0,
var guid: String = "",
var title: String = "",
var modified: Date,
var creation: Date
)
my import.sqlfile is located under ..\.\resources. it looks like this:
insert into calculation_type (guid, title, modified, creation) VALUES ("test", "title", "2013-12-12", "2013-12-12");
I am getting an error in German, traslated it says Column »test« does not exist.
Thats quite strange because test is in my values, not in my column definitions.
Does anyone know whats going on?
Character constants need single quotes
insert into calculation_type (guid, title, modified, creation) VALUES ('test", 'title', '2013-12-12', '2013-12-12');

Having issue while updating a column value of a table using uuid column in where clause

When I try to update a column value, with a uuid column in the where clause, I'm getting an error.
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I am using spring boot with native query. Here is the native query:
#Query(value = "UPDATE employee " +
"SET status = :status where employeeId = :employeeId", nativeQuery = true)
#Transactional
#Modifying
void updateROGS(#Param("status") String status, #Param("employeeId") UUID employeeId);
Would it be worth casting the employeeId to type text for easier comparison and then sending your parameter in as a String?
Something like;
#Query(value = "UPDATE employee " +
"SET status = :status where employeeId::text = :employeeId", nativeQuery = true)
#Transactional
#Modifying
void updateROGS(#Param("status") String status, #Param("employeeId") String employeeId);

DDL source Z1127_EXTVIEW of type ABAP Dictionary Type cannot be converted to Extend (-> long text)

I have the table Z1127_STUDENT:
define table z1127_student {
key id : z1127_sample not null;
branch : z1127_sample1;
age : z1127_age;
address : z1127_address;
percentage : z1127_percent;
}
(the types of the columns are based on the types int2 and char)
and the CDS view Z1127_CDS_VIEWS:
#AbapCatalog.sqlViewName: 'Z1127_CDSVIEWS'
#AbapCatalog.compiler.compareFilter: true
#AbapCatalog.preserveKey: true
#AccessControl.authorizationCheck: #CHECK
#EndUserText.label: 'CDS VIEWS'
define view Z1127_CDS_VIEWS as select from z1127_student
{
key id,
branch,
age
}
I tried to create this extended view :
#AbapCatalog.sqlViewAppendName: 'Z1127_SQL_3'
#EndUserText.label: 'cds view 3'
extend view Z1127_CDS_VIEWS with z1127_cds3 {
address,
percentage
}
But it's showing this error :
DDL source z1127_cds3 of type ABAP Dictionary Type cannot be converted to Extend (-> long text)
How to avoid this error?