i used Apollo in ReactNative Project
i want get some products from server with Query component in ApolloClient , my query schema is some thing like this
products(isExisting:true) {
id
name
}
this Query give me all available products and also i have this query too with different Argument
products(minPrice:$price)
id
name
}
now i want create program for conditional for choose between 2 Arguments , in Plane [A] use (isExisting) arg and in Plane [B] use (minPrice)
my first and stupid solution is create 2 different query component , is it any other way , for example set Variable for arguments like this
products($choose:$value)
also i know about directive in graphql https://graphql.github.io/learn/queries/#directives
but i think this is just for field
also my second solution for resolve this put javascript variable in `` , like this
render() {
const arg = 'minPrice';
return(
<Query
variables={{ }}
query={gql`
query {
products(${arg}:100) {
id
name }
i am checked this , working well for me , but i want know this is good and better way
I think last solution , is good idea for doing this approach , also you must know directive just working for filed
products(isExist:true) {
name #include if(false/true)
}
this means if conditions return True you get ( name ) field and if return False , ( name ) field not included in your query
also you can this directive
products(isExist:true) {
name #skip if(false/true)
}
#include(if: Boolean) Only include this field in the result if the argument is true.
#skip(if: Boolean) Skip this field if the argument is true.
Related
Summary:
I am working with a large JSON that is stored in a redshift SUPER type.
Context
This issue is near identical to the question posted here for TSQL. My schema:
chainId BIGINT
properties SUPER
Sample data:
{
"chainId": 5,
"$browser": "Chrome",
"token": "123x5"
}
I have this as a column in my table called properties.
Desired behavior
I want to be able to retrieve the value 5 from the chainId key and store it in a BIGINT column.
What I've tried
I have referenced the following aws docs:
https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html
https://docs.aws.amazon.com/redshift/latest/dg/r_SUPER_type.html
https://docs.aws.amazon.com/redshift/latest/dg/super-overview.html
I have tried the following which haven't worked for me:
SELECT
properties.chainId::varchar as test1
, properties.chainId as test2
, properties.chainid as test3
, properties."chainId" as test4
, properties."chainid" as test5
, json_extract_path_text(json_serialize(properties), 'chainId') serial_then_extract
, properties[0].chainId as testval1
, properties[0]."chainId" as testval2
, properties[0].chainid as testval3
, properties[0]."chainid" as testval4
, properties[1].chainId as testval5
, properties[1]."chainId" as testval6
FROM clean
Of these, the attempt, serial_then_extract returned a not null, correct value, but not all of the values in my properties field are short enough to serialize, so this only works on some of the rows.
All others return null.
Referencing the following docs: https://docs.aws.amazon.com/redshift/latest/dg/query-super.html#unnest I have also attempted to iterate over the super type using partisql:
SELECT ps.*
, p.chainId
from clean ps, ps.properties p
where 1=1
But this returns no rows.
I also tried the following:
select
properties
, properties.token
, properties."$os"
from base
And this returned rows with values. I know that there is a chainId value as I've checked the corresponding key and am working with sample data.
What am I missing? What else should I be trying?
Does anyone know if this has to do with the way that the JSON key is formatted? [camelcase]
You need to enable case sensitive identifiers. By default Redshift maps everything to lower case for table and column names. If you have mixed case identifiers like in your super field you need to enable case sensitivity with
SET enable_case_sensitive_identifier TO true;
See: https://docs.aws.amazon.com/redshift/latest/dg/r_enable_case_sensitive_identifier.html
Here I have several functions that all just set a single field on a model record.
In a more dynamic language, I'd just have a single setter function and pass it the name of the field (as a string) and the value that I want to set on the model object.
Is there a way to pass the name of the field in Elm?
What's the Elm way of doing something like this?
type alias Patient =
{ id : String
, name : String
, dateOfBirth : String
, sex : String
... other fields
}
setPatientName : Patient -> String -> Patient
setPatientName patient value =
{ patient | name = value }
setPatientDateOfBirth : Patient -> String -> Patient
setPatientDateOfBirth patient value =
{ patient | dateOfBirth = value }
setPatientSex : Patient -> String -> Patient
setPatientSex patient value =
{ patient | sex = value }
... many others
-- idx is the index of the patient in the model (which is an array of patients)
-- UpdateCell is a variant of my Msg type, like this: UpdateCell Int (Patient -> String -> Patient) String
onInputHandler : Int -> (Patient -> String -> Patient) -> String -> Msg
onInputHandler idx setter inputText =
UpdateCell idx setter inputText
-- idx is the index of the patient in the model (which is an array of patients)
createTableRow : Int -> Patient -> Html Msg
createTableRow idx patient =
...
, input [ type_ "text", onInput (onInputHandler idx setPatientName), value patient.name ] []
, input [ type_ "text", onInput (onInputHandler idx setPatientDateOfBirth), value patient.dateOfBirth ] []
...
I'm currently using each of these functions as an event handler for input elements. So I need a function that I can use for handling the input event. Ideally, I'd define just a single function and use that single one for all the input elements and pass it the field I want to update on the patient record.
The short answer is "no". But this seems a bit like an XY problem. It's not clear what benefit you are trying to achieve since the full application of such a function would be longer than the equivalent record update expression:
setField "name" patient value
-- vs
{ patient | name = value }
and as a partially applied function is only slightly shorter than the equivalent anonymous function with shortened argument names:
setField "name"
-- vs
\r x -> { r | name = x }
Although the latter is significantly noisier with all the symbols.
There is also a short-hand function for getting a record field:
.name
-- vs
\r -> r.name
So there is some precedent for having a dedicated syntax for setter functions too, but unfortunately there is not. Likely because it would complicate the language, and the syntax in particular, for relatively little benefit. I'm therefore curious about what you're actually trying to accomplish.
Edit after question update:
Putting functions in the Msg is a very bad idea because it goes against the Elm Architecture. It makes the state transition opaque and won't work very well with the debugger. When something goes wrong you can still see the state before and after, but you'll have trouble understanding what happened, and why it happened, because that information is encoded in an opaque function which probably isn't the one it should be.
You'll also have trouble factoring your logic. If you need something to happen only when a certain field updates, you might have to put the logic in the view, or special-case that field by putting the logic for that in update while the rest is in view, for example. Either way, you're on the path to a messy code base.
You should generally use names for messages that describe what happened, not what to do, because that tends to lead to an imperative mindset. Instead of UpdateCell you could call it InputChanged, for example. Then instead of the function you should have an identifier for the field. Ideally a custom type, like InputChanged Name, but even a string will work, though it will be much easier to miss a typo.
So instead of setter functions for each field you'll just case match the message and set the field in the update function:
InputChanged Name value ->
{ patient | name = value }
-- vs
setPatientName : Patient -> String -> Patient
setPatientName patient value =
{ patient | name = value }
Then if you need to clear the sex when the name changes, for example (because reasons...), you can simply do:
InputChanged Name value ->
{ patient | name = value, sex = "" }
The Elm Architecture is good because it makes changes easy and safe, not because it's concise and free of boiler-plate. Good Elm code often has a lot of copy-and-paste, but that's not always bad.
I have following snippet of code:
UserDataModel
.find {
UserDataTable.type eq type and (
UserDataTable.userId eq userId
)
}
.limit(count)
.sortedByDescending { it.timestamp }
sortedByDescending is a part of kotlin collections API. The my main concern is: how does exposed lib return top (according to timestamp) count rows from table if select query looks like this and does not contain ORDER BY clause?
SELECT USERDATA.ID, USERDATA.USER_ID, USERDATA.TYPE,
USERDATA.PAYLOAD, USERDATA."TIMESTAMP"
FROM USERDATA
WHERE USERDATA.TYPE = 'testType'
and USERDATA.USER_ID = 'mockUser'
LIMIT 4
And is it possible that sometimes or somehow returned result would be different for the same data?
Really struggled here. Thank you in advance.
You're sorting the results after query has been executed.
You need to use orderBy method as described in docs
UserDataModel
.find {
UserDataTable.type eq type and (UserDataTable.userId eq userId)
}
.limit(count)
.orderBy(UserDataTable.timestamp to SortOrder.DESC)
Is there a way to access the import parameters passed into a function module without addressing them individually? Does ABAP store them in some internal table, so I can work with them by looping through rows in some table, or fields of a structure?
We can use the PATTERN function, knowing only the function module's name, to have ABAP print out the function module's interface for us, so I'm wondering where this information is stored and if I can work with it once the function group has been loaded into memory.
Thanks in advance!
You can use the function module RPY_FUNCTIONMODULE_READ to obtain information about the parameter structure of a function module and then access the parameters dynamically. This has several drawbacks - most noticeably, the user doing so will need (additional) S_DEVELOP authorizations, and logging this way will usually impose a serious performance impact.
I'd rather add the function module parameters to the logging/tracing function manually once - with a sufficiently generic method call, it's not that difficult. I also tend to group individual parameters into structures to facilitate later enhancements.
PARAMETER-TABLE construct exists in ABAP since ancient times, it allows passing params in batch:
One should create two parameter tables of types abap_func_parmbind_tab and abap_func_excpbind_tab and fill them like this:
DATA: ptab TYPE abap_func_parmbind_tab,
etab TYPE abap_func_excpbind_tab,
itab TYPE TABLE OF string.
ptab = VALUE #(
( name = 'FILENAME' kind = abap_func_exporting value = REF #( 'c:\text.txt' ) )
( name = 'FILETYPE' kind = abap_func_exporting value = REF #( 'ASC' ) )
( name = 'DATA_TAB' kind = abap_func_tables value = REF #( itab ) )
( name = 'FILELENGTH' kind = abap_func_importing value = REF #( space ) ) ).
etab = VALUE #( ( name = 'OTHERS' value = 10 ) ) .
CALL FUNCTION 'GUI_DOWNLOAD'
PARAMETER-TABLE ptab
EXCEPTION-TABLE etab.
Instead of writing a query like
select * from xyz where mydomain IN ('foobar.com', 'www.example.com')
I want to write a function like
select * from xyz where one_of_my_domains(select mydomain as from_site)
But I want to be able to reuse this functions for any url in one of many tables. Currently when I use a function like this, I have to predefined what is returned and use it on the whole FROM part of the SQL statement. Is there any way to generalize a UDF to where I can use it on just 1 column instead of it operating over all rows. Here is my code right now that works but I have to predefine every output column which makes it not reusable.
domains = ['foobar.com', 'www.example.com'];
// The UDF
function has_domain(row, emit) {
var has_domain = false;
if (row.to_site !== null && row.to_site !== undefined) {
for (var i = 0; i < domains.length; i++){
if (domains[i] === String.prototype.toLowerCase.call(row.to_site)){
has_domain = true;
break;
}
}
}
return emit({has_domain: has_domain, trackingEventId: row.trackingEventId, date: row.date, from_site: row.from_site, to_site: row.to_site});
}
// UDF registration
bigquery.defineFunction(
'has_domain', // Name used to call the function from SQL
['from_site'], // Input column names
// JSON representation of the output schema
[{name: 'has_domain', type: 'boolean'}],
has_domain // The function reference
);
It might look a little messy - but below does exactly what you asked!
Make sure you are in Standard SQL (see Enabling Standard SQL)
CREATE TEMPORARY FUNCTION one_of_my_domains(x STRING, a ARRAY<STRING>)
RETURNS BOOLEAN AS
(x IN (SELECT * FROM UNNEST(a)));
WITH xyz AS (
SELECT 1 AS id, 'foobar.com' AS mydomain UNION ALL
SELECT 2 AS id, 'www.google.com' AS mydomain
),
site AS (
SELECT 'foobar.com' AS domain UNION ALL
SELECT 'www.example.com' AS domain
)
SELECT *
FROM xyz
WHERE one_of_my_domains(mydomain, ARRAY((SELECT domain FROM site)))
You're looking for scalar UDFs using standard SQL. They're much less awkward to use compared to those of legacy SQL.