How can I create a table with ReplicatedReplacingMergeTree engine on clickhouse? - database

I've been used clickhouse for a while, but it really confused me a lot.
So the problem is, when I'm trying to create a table with ReplicatedReplacingMergeTree engine, I set the engine as ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/tableName/{shard}/', '{replica}'), which included the param for ReplicatedMergeTree, but I don't know how to set the param for ReplacingMergeTree part.
I found no answer on documentations, which is sucks.
Anybody can help me?

create table test (D Date, ID Int64, Ver UInt64)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/tableName/{shard}/',
'{replica}', Ver)
partition by toYYYYMM(D)
order by ID

Related

not clause in neo4j as recommendation engine

I am able to create relationship between material and the enduser who bought it using below code
match (n:demodb)
merge (f:material {id:n.material})
merge (t:enduser {id:n.endUser})
create (f)-[r:BOUGHT]->(t) return f,t limit 100;
but now I want to find materials not bought by enduser and show as recommendation engine in graph. I am new to cypher and Neo4J . please suggest
I tried using Not clause but its not working or may be I am missing
You can try NOT predicate as such:
MATCH(f:material),(t:enduser) WHERE NOT (f)-[:BOUGHT]->(t) return f,t

How to Create a Currency and Inventory System in Discord.js

So I've been trying to make a currency system and an inventory system for my Discord bot for the past few days. However, I can't seem to make any progress at all. I've tried using sequelize and better-sqlite3 (which is what I'm currently using), all with no success.
const table = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type ='table' AND name = 'balance';").get();
if (table["count(*)"] === 0) {
console.log("creating table...");
sql.prepare("CREATE TABLE scores (id TEXT PRIMARY KEY, user TEXT, guild TEXT, money INTEGER);").run();
sql.prepare("CREATE UNIQUE INDEX idx_scores_id ON scores (id);").run();
sql.pragma("synchronous = 1");
sql.pragma("journal_mode = wal");
}
client.getScore = sql.prepare("SELECT * FROM balance WHERE user = ? AND guild = ?");
client.setScore = sql.prepare("INSERT OR REPLACE INTO money (id, user, guild, money) VALUES (#id, #user, #guild, #money);");
The above code results in this error:
(node:13036) UnhandledPromiseRejectionWarning: SqliteError: table scores already exists
I don't have that much knowledge on stuff like this since there is so little material out there for me to refer to.
This is a bad approach to validate tables. You should use IF NOT EXISTS instead. See this question for reference:
From http://www.sqlite.org/lang_createtable.html:
CREATE TABLE IF NOT EXISTS some_table (id INTEGER PRIMARY KEY AUTOINCREMENT, ...);
You can also use IF NOT EXISTS for your index.
In the future I recommend focusing on the specific technology you're having issues with when researching and asking questions. There is in fact plenty of material out there about proper usage patterns for sqlite - but you have to search and ask specifically for sqlite.
In this question, for example, you ask about making a currency and inventory system in discord.js, but there is no discord.js code here, the error is a sqlite error, and searching for "how to create table only if it doesn't exist sqlite" would have brought you to the links above. In short, search for the specific technology you're using, not for the whole project.
That being said, there is also an "official unofficial" resource on creating a currency system with discord.js here: https://discordjs.guide/sequelize/currency.html - but it uses sequelize, so you may not find it as helpful.

Use of Maps in Flink SQL

If you register a table and one of its fields is a map (extra in this case“) the following statement works just fine:
SELECT f1, f2 FROM customers WHERE extra['sportPrefs'] = 'Football';
Now try to reference a key that does not exist in the map.
SELECT f1, f2 FROM customers WHERE extra['moviePrefs'] = 'Action';
You will get an NPE and the job exits. This would be OK if there was a way to check whether a particular key exists in a map. Unfortunately, I have not found a way. Check for IS NOT NULL does not work. Without this feature maps in Flink SQL are pretty useless. What am I missing? Thanks!
What you do describe was a bug that is described here.
It will be fixed in the next Flink version 1.5.0 that will be released next month.

Why is geosearching/location based searches returning zero results?

I am trying to use app engine's search API to search locations:
https://developers.google.com/appengine/docs/python/search/overview#Performing_Location-Based_Searches
The problem is no matter what I do, I get zero results. I set the search lat/lng as the the exact point on a document's GeoPoint property and it still returns zero.
I know the regular search is working because if I change the query to be a regular full-text search, it works.
Here is an example of my data (this is actually from the example app here: http://www.youtube.com/watch?v=cE6gb5pqr1k)
Full Text Search > stores1
Document Id: sanjose
Field Name Field Value
store_address 123 Main St.
store_location search.GeoPoint(latitude=37.37, longitude=-121.92)
store_name San Jose
And then my query:
index = search.Index('stores1')
loc = (37.37, -121.92)
query = "distance(store_location, geopoint(37.37, -121.92)) < 4500"
loc_expr = "distance(store_location, geopoint(37.37, -121.92))"
sortexpr = search.SortExpression(
expression=loc_expr,
direction=search.SortExpression.ASCENDING, default_value=4501)
search_query = search.Query(
query_string=query,
options=search.QueryOptions(
sort_options=search.SortOptions(expressions=[sortexpr])))
results = index.search(search_query)
print results
And the returns:
search.SearchResults(number_found=0L)
Am I missing something or doing something wrong? This should return at least that one result, right?
** UPDATE **
After doing some prying/searching/testing I think this may be a bug regarding the google app engine development server.
If I run location searches on the same data in the production environment, I get expected results. When I compare and run the exact same query on the data in the development environment, I get the unexpected 0 results.
If anybody has any insight on this, please advise. Otherwise, for those of you seeing the same problem, I created an issue on app engine's issue tracker
here.
You've probably already figured this out, but in case someone comes across this post, the geosearch feature of AppEngine's Search API returns zero results on the dev server. From https://developers.google.com/appengine/training/fts_intro/lesson2:
"...some search queries are not fully supported on the Development Web Server (running locally), so you’ll need to run them using a deployed application."
Here's another useful link:
https://developers.google.com/appengine/docs/python/search/devserver

Google app engine: Retrieve values from datastore after a particular key value?

I'm newbie to GAP (Python). I'm using NDB to retrieve all the values from datastore which comes after a particular key value.
Thanks in advance if anybody can help me out with this one?
I assume you are setting the key or are using allocate id's otherwise such a requirement would not have a lot of meaning.
You can use the key as an order argument.
e.g. I have a Product model
x = models.Product.query().order(models.Product.key)
Given this I can then get all keys greater than a specific key with
x = models.Product.query(models.Product.key > ndb.Key('Product','001132')).order(models.Product.key)
The order is a bit irrelevent but heh ;-)

Resources