Ignite SQL error 50000 when inserting on refence table - mariadb

I'm currently researching on Ignite, and I used web-console's automatic RDBMS integration feature for my MariaDB persistent store.
This made ignite configure a cache for one of my reference table which has a many-to-many relationship, with 2 fields, both primary-keys.
Example Structure in the persistent store:
CREATE TABLE `user_category` (
`USER_ID` bigint(20) NOT NULL,
`CATEGORY` bigint(20) NOT NULL,
PRIMARY KEY (`USER_ID`,`CATEGORY`),
KEY `FK48520EF2B4BDA303` (`USER_ID`),
KEY `FK48520EF2C941D634` (`CATEGORY`),
CONSTRAINT `FK48520EF2B4BDA303` FOREIGN KEY (`USER_ID`) REFERENCES `ctrl_app_user` (`USER_ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK48520EF2C941D634` FOREIGN KEY (`CATEGORY`) REFERENCES `request_category` (`CATEGORY_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This made web-console configure the cache like this:
ArrayList<QueryEntity> qryEntities = new ArrayList<>();
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType("model.UserCategoryKey");
qryEntity.setValueType("model.UserCategory");
qryEntity.setTableName("user_category");
HashSet<String> keyFields = new HashSet<>();
keyFields.add("userId");
keyFields.add("category");
qryEntity.setKeyFields(keyFields);
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("userId", "java.lang.Long");
fields.put("category", "java.lang.Long");
qryEntity.setFields(fields);
HashMap<String, String> aliases = new HashMap<>();
aliases.put("userId", "USER_ID");
qryEntity.setAliases(aliases);
ArrayList<QueryIndex> indexes = new ArrayList<>();
QueryIndex index = new QueryIndex();
index.setName("FK48520EF2B4BDA303");
index.setIndexType(QueryIndexType.SORTED);
LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>();
indFlds.put("userId", false);
index.setFields(indFlds);
indexes.add(index);
index = new QueryIndex();
index.setName("FK48520EF2C941D634");
index.setIndexType(QueryIndexType.SORTED);
indFlds = new LinkedHashMap<>();
indFlds.put("category", false);
index.setFields(indFlds);
indexes.add(index);
qryEntity.setIndexes(indexes);
qryEntities.add(qryEntity);
ccfg.setQueryEntities(qryEntities);
return ccfg;
I am able to retrieve data from ignite properly using its standard SQL.
However, when trying to insert data to that cache, I am getting error 50000 which according to Ignite documentation, is a query that is unsupported by ANSI-99.
Documentation also mentioned to take a look into the SQLException message but the message only mentioned the error 50000.
sample insert statement:
insert into USER_CATEGORY (USER_ID, CATEGORY) values (1, 1);
Thanks in Advance.

Most likely you need to specify a schema name (cache name) for the query:
insert into "YourCacheName".USER_CATEGORY (USER_ID, CATEGORY) values (1, 1);

So, for everyone who will experience this issue in the future, I've resolved the issue by removing the query entity keys.
keyFields.add("userId");
keyFields.add("category");
Ignite treats keys in a reference table/cache as unique, so both columns needed to be unique, this is not applicable for reference tables with many-to-many relationship since this design is bound to have duplicates for each column.
Thanks for those who took a look at this issue!~

Related

SQL.js Instead of creating a new sql database , access a file.sql

I need help (Problem inside code.)
var db = new SQL.Database(); //instead of creating a new Database , i want to access one.
db.run("CREATE TABLE todos (id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT);");```

What is the Partiton Key value when it's null?

I've got records that were the result of bad data where the Partition Key is null and I need to clean them up, but I've been unsuccessful so far.
Here's what I've tried:
var scriptResult = await _dbClient.ExecuteStoredProcedureAsync<dynamic>(
GetStoredProcLink("BulkDelete"),
new RequestOptions() { PartitionKey = new PartitionKey(""), EnableScriptLogging = true },
"select * from c where c.documentDbType = "SomeValue"");
I've also tried used Undefined.Value as the parameter to new PartitionKey().
I ripped the stored proc from here and haven't changed anything yet.
Note: This is a partitioned collection if it was not obvious (by /companyId)
I just hit this issue when migrating to new database level throughput provision. This is syntax that got me up and running again when my models did not contain the specified partition Key property:
new RequestOptions() {
PartitionKey = new PartitionKey(Undefined.Value)
}
Ref:
https://www.lytzen.name/2016/12/06/find-docs-with-no-partitionkey-in-azure.html
Null, Undefined, and empty string are all different values in Cosmos DB. You need something like: new RequestOptions { PartitionKey = new PartitionKey(null) }

Delete items from dynamodb based on date

I am new to dynamodb, I am able to delete an item based on key.
Below is the code snippet:
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("hash", new AttributeValue().withS("hashEncodedStringValue"));
DeleteItemRequest deleteItemRequest = new DeleteItemRequest().withTableName("HashTable").withKey(key);
I need to delete items less than 7 days old from my table. And my table has a field called 'created_at' in this format "2017-10-25 14:54:52.278"
If you want dynamodb to delete it automatically after 7 days you can create TTL field and update the timestamp, dynamodb will automatically delete it.
Reference:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html
CRUD Operations with Java:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html
Hope it helps.

ASP Core 1 with PostgreSql. Authorizatioin and authentication

I have a web application based on ASP Core 1 with PostgreSql data storage. And now i want to add auth functionality. I have created base example mvc project with authorization and it works fine with MsSql server. But what about PostgreSql?
At first i create database with same schema (sql was generated via dnx ef migrations script and code was updated with pg-style). Then i have configured EF with Postgres
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(Configuration["Data:DefaultConnection:ConnectionString"]));
When i try to register as new user, i get an error 42P01: relation \"AspNetUsers\" does not exist. I have already surrounded table name with doublequotes, but it does not helps. I have no access to default auth models and can't add name atribute to table name and name of fields.
So, my questions are:
What wrong with my sample project and why i can't get access to db?
More globally. What is the best way to organize authorization and authentication with ASP Core 1 + PostgreSql? I no needed in all ASP auth features, i just neede in roles, i want to have bigint-based id and i want to extend users model (table).
Note: I use EF7.
So the answer for my first question is in the wrong database schema. For someone interested in schema i get the full pg sql code, but my second question is still opened.
CREATE TABLE public."AspNetRoles" (
"Id" character varying(450) NOT NULL,
"ConcurrencyStamp" text,
"Name" character varying(256),
"NormalizedName" character varying(256),
CONSTRAINT pk_identityrole PRIMARY KEY ("Id")
);
CREATE TABLE public."AspNetUsers" (
"Id" character varying(450) NOT NULL,
"AccessFailedCount" integer NOT NULL,
"ConcurrencyStamp" text,
"Email" character varying(256),
"EmailConfirmed" boolean NOT NULL,
"LockoutEnabled" boolean NOT NULL,
"LockoutEnd" timestamp without time zone,
"NormalizedEmail" character varying(256),
"NormalizedUserName" character varying(256),
"PasswordHash" text,
"PhoneNumber" text,
"PhoneNumberConfirmed" boolean NOT NULL,
"SecurityStamp" text,
"TwoFactorEnabled" boolean NOT NULL,
"UserName" character varying(256),
CONSTRAINT pk_applicationuser PRIMARY KEY ("Id")
);
CREATE TABLE public."AspNetRoleClaims" (
"Id" serial NOT NULL,
"ClaimType" text,
"ClaimValue" text,
"RoleId" character varying(450),
CONSTRAINT pk_identityroleclaim PRIMARY KEY ("Id"),
CONSTRAINT fk_identityroleclaim_identityrole_roleid FOREIGN KEY ("RoleId")
REFERENCES public."AspNetRoles" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserClaims" (
"Id" serial NOT NULL,
"ClaimType" text,
"ClaimValue" text,
"UserId" character varying(450),
CONSTRAINT pk_identityuserclaim PRIMARY KEY ("Id"),
CONSTRAINT fk_identityuserclaim_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserLogins" (
"LoginProvider" character varying(450) NOT NULL,
"ProviderKey" character varying(450) NOT NULL,
"ProviderDisplayName" text,
"UserId" character varying(450),
CONSTRAINT pk_identityuserlogin PRIMARY KEY ("LoginProvider", "ProviderKey"),
CONSTRAINT fk_identityuserlogin_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserRoles" (
"UserId" character varying(450) NOT NULL,
"RoleId" character varying(450) NOT NULL,
CONSTRAINT pk_identityuserrole PRIMARY KEY ("UserId", "RoleId"),
CONSTRAINT fk_identityuserrole_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_identityuserrole_identityrole_roleid FOREIGN KEY ("RoleId")
REFERENCES public."AspNetRoles" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
I transfer my database from SQL SERVER to postgreSQL, after transfer, I found this error. when I checked my database, the table was in lowercase. I changed all AspTables and columns to default name and solved my problem.

How to query range key programmatically in DynamoDB

How to query range key programmatically in DynamoDB, I am using .Net AWSSDK ,I am able to query on Hash key with below code :
GetItemRequest request = new GetItemRequest
{
TableName = tableName
};
request.Key = new Dictionary<string,AttributeValue>();
request.Key.Add("ID",new AttributeValue { S = PKValue });
GetItemResponse response = client.GetItem(request);
Please suggest,
Thanks in advance.
There are two kinds of primary key in DynamoDB: Hash-only or Hash-Range.
In the above code I guess your table is Hash-only and you use the hash key to retrieve an element with hashkey equals to PKValue.
If your table is in H-R schema and you want to retrieve a specific element with a hashKey and rangeKey, you can reuse the above code and in addition, add the {"RangeKey", new AttributeValue } into your your request.KEY
On the other hand, query means a different thing in DynamoDB. Query will return you a list of rows sorted in some order.

Resources