I loaded my dataset by csv file name moviestoactors.csv with this particular command
LOAD CSV FROM 'file:///desktop-csv-import/moviestoactors.csv' AS row
WITH row[0] AS movieId, row[1] AS actorId, row[2] AS as_character, row[3] AS leading
MERGE (m:moviestoactors {movieId:movieId })
SET m.actorId = actorId, m.as_character = as_character, m.leading = leading
RETURN count(m)
The first problem i faced was that i was not able to load actorId as toInteger(row[1]) as actorId since it was showing syntax error like it is out of bound since the value of integer is too much large for integer to handle, and i did not find any solution for that so i decided to load actor id as string.
Now if i want to match some id with anysort of id, i am not able to i dont know what is it but it is not working properly even though i checked my csv file and it had that id 9 times,
for instance this is actorId 244663, this is my query which is not working, what should work then?
MATCH(ma:moviestoactors)
WITH ma.movieId AS movieId WHERE ma.actorId = '244663'
return movieId
To summarize the whole thing, first problem is how to get my id to be in integer form and the second thing if it is not in integer why it is not even matching in string form.
Related
My table looks like this,
CREATE TABLE IF NOT EXISTS names (
firstname text,
surname text,
id text,
PRIMARY KEY (firstname, surname)
)
Let's say I want to return a minimum of 10 names.
I do
select * from names where firstname = "something" and surname "something";
But if this only returns 6 people, I then want it to do:
select * from names where firstname = "something" limit 4;
But I want to avoid returning the same row twice.
And possibly do it in one query only.
Is this possible?
You may use SELECT "DISTINCT" feature of CQLSH. you will get unique value for partitions. Also please refer below documentations for more understanding:-
https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cql_commands/cqlSelect.html
You can rely on the paging implemented by driver(s), for example, in Java.
In your case, you can perform query, and use .setFetchSize when performing specific query to some value you need - in this case, driver will read approximately specified number (or less) as a first page, and if you'll need more, then you can proceed iterating over results, and driver will fetch next page, until either you stop, or there will be no more data.
But be very careful with too low values of the page - if you have a lot of data in partition, then driver will need to go to Cassandra very often, and this will impact performance.
P.S. you can't have 10 records for query where firstname = "something" and surname = "something", because both columns comprise full primary key, and there could be only one record for given primary key. You may use something like where firstname = "something" and surname >= "something" to fetch data starting with given surname.
This is the question asked in the homework
Write SQL to remove 'Airlines' from any carrier that has it. For example, if 'Delta Airlines' is in the table, your SQL should change that value to just 'Delta'. This must be a single query that addresses all records that have 'Airlines' in them, and should fix them all at the same time. It must be written with the assumption that other records containing 'Airlines' could exist, and if they did exist, it should address them as well.
The table I currently have for airlines has 6 airlines listed and only two contain the word airline. In the table there are two columns AirlineID and AirlineName. How do I delete the second word from the AirlineName column?
I tried
Update Airlines
Set AirlineName =
Case
When AirlineName = 'Southwest Airlnes' Then 'Southwest'
When AirlineName = 'Frontier Airlines' Then 'Frontier'
End
However after running this it set every record in the AirlineName record to NULL.
I think this is what you are looking for:
Update Airlines
Set AirlineName = Replace (AirlineName,'Airlnes','')
And, you can also try this without using the replace function. In this below query do not need to pass the hardcoded string like 'Airlnes'.
Update Airlines
Set AirlineName = SUBSTRING(Airlinename,1,(CHARINDEX(' ',Airlinename + ' ')-1))
I use Parse.com Core and Cloud Code to store data and perform some operations for a mobile app. I have an issue with a query on an array field that is sometimes not returning anything even if I am sure it should.
I store a large amount of phone numbers in an array field to keep track of user's matching contacts.
This field is called phoneContacts and look like this (with numbers only, this is just as an example):
["+33W30VXXX0V","+33W30VXX843","+33W30VZVZVZ","+33W34W3X0Y4","+33W34W386Y0", ...]
I have a function in Cloud Code that is supposed to get matching rows for a given phone number. Here is my query:
var phoneNumber = request.params.phoneNumber;
var queryPhone = new Parse.Query('UserData');
queryPhone.equalTo('phoneContacts', phoneNumber); // phoneNumber is passed as a string param, i.e. "+33W30VXX843"
queryPhone.include('user');
var usersToNotify = [];
return queryPhone.each(function(userData) {
var user = userData.get('user');
usersToNotify.push(user.get('username'));
})
.then(function() {
return usersToNotify;
});
I tested my query with an array of 2 or 3 phone numbers and it works well and returns the expected rows. But then I tried with a user having around 300 phone numbers in that phoneContacts field and even if I query a value that is present (appear with a filter in Parse Data Browser), nothing is returned. To be sure I even took a phone number existing in 2 rows: one with few values and one with many, and only the row with a few values got returned.
I've read carefully the Parse documentation and especially about queries and field limits, but it doesn't seem to have a restriction on the number of values for an array field, and nothing says that query might not work with a lot of values.
Anybody can point me in the right direction? Should I design my Parse Classes differently to avoid having so many values in an array field? Or is there something wrong with the query?
You need to be using a PFRelation or some sort of intermediate table. You should not use an array to store 300 phone numbers, your queries will get really slow.
PFRelations:
https://parse.com/docs/osx/api/Classes/PFRelation.html
http://blog.parse.com/learn/engineering/new-many-to-many/
If I make an SOQL query such as:
select Id, Username, UserRoleId from User
The API correctly returns the results as XML, however because none of the rows contain a UserRoleId entry this node is completely excluded from the results.
Ideally I would like to be able to create a table from the resultant XML showing all the requested columns, even if they are empty. Is there a way of forcing the API to return even empty columns so that I can do this without resorting to something messy like parsing the SOQL query?
Isn't it a better idea to when you receive an result. Check if the curtain column row is empty. When the column is empty, than you know you have set a empty column by yourself. It is just an idea of my.
Think about a try catch, just an example I use in my application:
try {
parentId = records.getJSONObject(i).getJSONObject("Parent).getString("Name");
catch (JSONException e) {
parentId = "a";
}
When the column name from Parent is empty, then parentId = a. I'd set it manually because I know some other data rolls could have that data.
Based on the documentation here:
http://docs.composite.net/Data/AccessingDataWithCSharp/How-to-Query-Data-Using-LINQ#_How_to_Query
I need to query data in a table using a filter in type string[int1,int2,int3..] and can't work out how to go about it.
The string[] comes from a different table field which stores id values of a multiselect element on a form:
Table 'Profile' (AGlobal.profile) contains columns:
Id Types(profile_accomtypes)
1 1,2
2 4,7
3 12,4,6
4 3,6,9
Then I have a static table 'TypeDesc' (ALocal.proptype) listing a total of 12 'Type' values:
Id Description(proptype_names)
1 The first description
2 The second description
........
12 The twelfth description
I created a strongly coded class enabling me to easily handle the form content on submit from the client. Within the form was a couple of multiselects (one of them being 'Types" above in the Profile datatype table.) Each of the multiselects are passed to the server in serialized JSON format where I string.Join the 'Types' values with a comma separator to save into the Profile.Types column.
Now I want to serve the selections in a profile page to the client by loading the Types string[] of Profile Id and using the int id values to filter the TypeDesc table to only select the Type values with Description so that I can render the descriptions as a bullet list on the client.
The filter Types in the Profile table are always id integers
My code I'm using is:
var myProftype =
(from d in connection.Get<AGlobal.profile>() // find multiselected type string values
where d.Id == StUserSet.utoken
select d).First();
string sProftype = myProftype.profile_accomtypes;
string[] sTypes = sProftype.Split(',');
// now filter proptypes to sTypes
var myTAccomtypes =
(from d in connection.Get<ALocal.proptype>() // get all the types from the DB
where(r => sTypes.Contains(r.Field<int>("Id"))) //Lambda ?
select d).All;
StringBuilder sb = new StringBuilder(0); //create a bullet list string
// Loop over strings
foreach (string s in myTAccomtypes)
{
sb.append("<dd>"+ s +"</dd>");
}
TuAccomtypes = sb.ToString(); // pass string to JQuery Taconite as part of AJAX response to alter DOM.
I have an error on the Lambda trying to filter my types.
In VS2010:
Error = Cannot convert lambda expression to type bool because its not a delegate type.
I also do not know how to go about parsing the sTypes variables to int (if I need to) so that the filter works :(
Where am I going wrong? Is there a cleaner way to filter a dataset against a comma separated list queried from a column field within a db table?
Thank you for any help/ideas in advance.
Martin.
I'm not entirely sure about your model, but I think this will work for you. I changed your linq, and combined some statements. I'm also casting your Id field to string so that it can be found correctly in the array.Contains() function. You might want to do the reverse of casting your strings to ints and comparing that way, but that's up to you.
var myProftype = profiles.First(p => p.Id == StUserSet.utoken);
string sProftype = myProftype.profile_accomtypes;
string[] sTypes = sProftype.Split(',');
var myTAccomtypes = propTypes.Where(r => sTypes.Contains(r.Field<int>("Id").ToString()));
StringBuilder sb = new StringBuilder(0);
foreach (PropType s in myTAccomtypes)
{
sb.Append("<dd>" + s.Description + "</dd>");
}
Once splitting the string var from the original Linq query (which identified a single field with a joined string of comma separated id numbers.) I wasn't able to use "Contains" properly.
I cast the second Linq query ToList which evaluated the collection.
Then instead of working with a full result I limited the result to just the id and name fields.
Relying on an article posted by Vimal Lakhera:
http://www.c-sharpcorner.com/uploadfile/VIMAL.LAKHERA/convert-a-linq-query-resultset-to-a-datatable/
I converted the result set into a DataTable which allowed easy looping and selection of fields to output as an html string as part of a JQuery Taconite callback.
Here's what works for me...
// now filter proptypes to selected Types|
var myTAccomtypes = from d in connection.Get<ALocal.proptype>().ToList()
// ToList() will evaluate collection, you cannot pass sTypes array of integers to a sql query, at least not in that way
where sTypes.Contains(d.proptype_id.ToString())
select new { d.proptype_id, d.proptype_name };
DataTable AcomType = LINQToDataTable(myTAccomtypes);
StringBuilder sb = new StringBuilder();
// Loop over table rows
foreach (var row in AcomType.Rows.OfType<DataRow>().Take(19)) // will .Take up to a maximum of x rows from above
{
sb.Append("<dd>");
sb.Append(row["proptype_name"].ToString());
sb.Append("</dd>");
}
HldUserSet.TuAccomtypes = sb.ToString();
//HldUserSet.TuAccomtypes = string.Join(",", myTAccomtypes); //Check query content
Using Vimal's 'LINQToDataTable" with the tweak in the LINQ request means that I can use the class in numerous places of the site very quickly.
This works a treat for those with a single string of joined id's in the form of "2,7,14,16" that need to be split and then used to filter against a wider collection matching the id's from the string to record id numbers in a different collection.