Saving to new cluster returns error - orientdb

I'm creating cluster dynamically in xtend/Java
for (int i : 0 ..< DistributorClusters.length) {
val clusterName = classnames.get(i) + clusterSuffix;
database.command(
new OCommandSQL('''ALTER CLASS «classnames.get(i)» ADDCLUSTER «clusterName»''')).execute();
}
Then I create I add the oRole and Grant the security to the new oRole
val queryOroleCreation = '''INSERT INTO orole SET name = '«clusterSuffix»', mode = 0, inheritedRole = (SELECT FROM orole WHERE name = 'Default')''';
val ODocument result = database.command(new OCommandSQL(queryOroleCreation)).execute();
for (int i : 0 ..< classnames.length) {
database.command(
new OCommandSQL(
'''GRANT ALL ON database.cluster.«classnames.get(i)»«clusterSuffix» TO «clusterSuffix»''')).
execute();
}
Finally I try to save a JsonObject to one of the newly created cluster. I checked in the database and the cluster exists.
val doc = new ODocument();
doc.fromJSON(jsonToSave.toString());
val savedDoc = database.save(doc, "ClassName"+clusterSuffix);
database.commit();
But Orient returns the following error :
SEVERE: java.lang.IllegalArgumentException: Cluster name 'cluster:ClassNameclusterSuffix' is not configured
My Question :
What causes that exception? And can you add values to new cluster created?
Edit
The doc object contains reference to other classes. i.e:
{
#class:"Customer",
#version:0,
name:"Kwik-E-Mart",
user : {
#class:"User",
#version:0,
username: "Apu",
firstName:"Apu",
lastName:"Nahasapeemapetilon"
}
}
The user gets created in the default cluster, but the customer throws the exception.

You should remove the "cluster:" part. The second parameter of the method is "Name of the cluster where to save", it doesn't need any special prefix.
So:
val savedDoc = database.save(doc, "ClassName"+clusterSuffix);
should just work

I find out that using a query works fine source.
The following code worked on the first try:
val query = '''INSERT INTO ClassNameCLUSTER «"ClassName"+clusterSuffix» CONTENT «jsonToSave.toString()»'''
val ODocument savedDoc = database.command(new OCommandSQL(query)).execute();

Related

c# - The given ColumnName 'xxxxxxx' does not match up with any column in data source

In my code has an issue but I can't see what issue in this. Column names are same word by word and it is working, If I use 1 column in csv file but when I try out more then 2-3 column fields it is giving the error below. I have checked read lots of article so I can't fix the error. What can be happen with is this lines. DB already was created with similar fields.
private void DBaktar()
{
string SQLServerConnectionString = "Server =.\\SQLEXPRESS; Database = Qiti; User Id = sa; Password = 7731231xx!!;";
string CSVpath = #"D:\FTP\"; // CSV file Path
string CSVFileConnectionString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};;Extended Properties=\"text;HDR=Yes;FMT=Delimited\";", CSVpath);
var AllFiles = new DirectoryInfo(CSVpath).GetFiles("*.CSV");
string File_Name = string.Empty;
foreach (var file in AllFiles)
{
try
{
DataTable dt = new DataTable();
using (OleDbConnection con = new OleDbConnection(CSVFileConnectionString))
{
con.Open();
var csvQuery = string.Format("select * from [{0}]", file.Name);
using (OleDbDataAdapter da = new OleDbDataAdapter(csvQuery, con))
{
da.Fill(dt);
}
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(SQLServerConnectionString))
{
bulkCopy.ColumnMappings.Add("LKod", "LKod");
bulkCopy.ColumnMappings.Add("info", "info");
bulkCopy.ColumnMappings.Add("Codex", "Codex");
bulkCopy.ColumnMappings.Add("LthNo", "LthNo");
bulkCopy.ColumnMappings.Add("Datein", "Datein");
bulkCopy.DestinationTableName = "U_Tik";
bulkCopy.BatchSize = 0;
bulkCopy.EnableStreaming = true;
bulkCopy.WriteToServer(dt);
bulkCopy.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Error exception;
The given ColumnName 'LKod' does not match up with any column in data
source.
ex.StackTrace;
at
System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerCommon(Int32
columnCount) at
System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32
columnCount, CancellationToken ctoken) at
System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table,
DataRowState rowState) at
System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table)
Some information can be found here: https://sqlbulkcopy-tutorial.net/columnmapping-does-not-match
Cause
You didn't provide any ColumnMappings, and there is more column in the source than in the destination.
You provided an invalid column name for the source.
You provided an invalid column name for the destination.
Solution
ENSURE to provide a ColumnMappings
ENSURE all values for source column name are valid and case sensitive.
ENSURE all values for destination column name are valid and case sensitive.
MAKE the source case insensitive
I have found a solution and working 100% true.. The link below, I hope become a path who need that.
https://johnnycode.com/2013/08/19/using-c-sharp-sqlbulkcopy-to-import-csv-data-sql-server/

Calling a custom function in Rasa Actions

I am facing a problem in developing a chatbot using rasa .
I am trying to call a custom function in rasa action file. But i am getting an error saying "name 'areThereAnyErrors' is not defined"
here is my action class. I want to call areThereAnyErrors function from run method. Could someone please help how to resolve this?
class ActionDayStatus(Action):
def areThereAnyErrors(procid):
errormessagecursor = connection.cursor()
errormessagecursor.execute(u"select count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T = :messageT",{"procid": procid, "messageT": 'E'})
counts = errormessagecursor.fetchone()
errorCount = counts[0]
print("error count is {}".format(errorCount))
if errorCount == 0:
return False
else:
return True
def name(self):
return 'action_day_status'
def run(self, dispatcher, tracker, domain):
import cx_Oracle
import datetime
# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
conn_str = dbconnection
connection = cx_Oracle.connect(conn_str)
cursor = connection.cursor()
dateIndicator = tracker.get_slot('requiredDate')
delta = datetime.timedelta(days = 1)
now = datetime.datetime.now()
currentDate = (now - delta).strftime('%Y-%m-%d')
print(currentDate)
cursor = connection.cursor()
cursor.execute(u"select * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})
all_files = cursor.fetchall()
total_number_of_files = len(all_files)
print("total_number_of_files are {}".format(total_number_of_files))
Answer given by one of the intellectuals :
https://realpython.com/instance-class-and-static-methods-demystified/ Decide whether you want a static method or class method or instance method and call it appropriately . Also when you are using connection within the function it should be a member variable or passed to the method You dont have self as a parameter so you may be intending it as a static method - but you dont have it created as such

How to remove JanusGraph index?

but the index status is installed,how to change the status to registed and then disable it to remove it please help me ,
GraphTraversalSource g = janusGraph.traversal();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
JanusGraphIndex phoneIndex =
janusGraphManagement.getGraphIndex("phoneIndex");
PropertyKey phone = janusGraphManagement.getPropertyKey("phone");
SchemaStatus indexStatus = phoneIndex.getIndexStatus(phone);
String name = phoneIndex.name();
System.out.println(name);
if (indexStatus == INSTALLED) {
janusGraphManagement.commit();
janusGraph.tx().commit();
If you are unable to change the status of index from Install to Enable, I suggest you to check the running instances of JanusGraph and close all the instances except the one with "(Current)" and then try again removing the index.
To check and close instances use following command in gremlin shell:
mgmt = graph.openManagement()
mgmt.getOpenInstances() //all open instances
==>7f0001016161-dunwich1(current)
==>7f0001016161-atlantis1
mgmt.forceCloseInstance('7f0001016161-atlantis1') //remove an instance
mgmt.commit()
To remove the index use following code:
// Disable the "name" composite index
this.management = this.graph.openManagement()
def nameIndex = this.management.getGraphIndex(indexName)
this.management.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX).get()
this.management.commit()
this.graph.tx().commit()
// Block until the SchemaStatus transitions from INSTALLED to REGISTERED
ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.DISABLED).call()
// Delete the index using JanusGraphManagement
this.management = this.graph.openManagement()
def delIndex = this.management.getGraphIndex(indexName)
def future = this.management.updateIndex(delIndex, SchemaAction.REMOVE_INDEX)
this.management.commit()
this.graph.tx().commit()
I faced the same issue and tried a lot of other things then finally the above procedure worked!
Index has to be disabled first then it could be removed.
// Disable the "phoneIndex" composite index
janusGraphManagement = janusGraph.openManagement()
phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
janusGraphManagement.updateIndex(phoneIndex, SchemaAction.DISABLE_INDEX).get()
janusGraphManagement.commit()
janusGraph.tx().commit()
// Block until the SchemaStatus transitions from INSTALLED to REGISTERED
ManagementSystem.awaitGraphIndexStatus(janusGraph, 'phoneIndex').status(SchemaStatus.DISABLED).call()
// Delete the index using TitanManagement
janusGraphManagement = janusGraph.openManagement()
phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
future = janusGraphManagement.updateIndex(phoneIndex, SchemaAction.REMOVE_INDEX)
janusGraphManagement.commit()
janusGraph.tx().commit()

OrientDB fails to persist a Vertex, returns ORID but with null vertex eg v(null)[#3:4]

I cant get OrientDB to persist an OrientVertex or an oDocument using the java API.
although its works when I use SQL and the OCommand.
trying to persist a vertex with foll code
val factory: OrientGraphFactory = new OrientGraphFactory("plocal:localhost/database", "admin", "admin");
val graph = factory.getTx
val oDocument: ODocument = UserEntityMapper.toODocument(user)
println("ODocument = = "+ oDocument)
val orientVertex = new OrientVertex(graph, oDocument)
println("BEFORE orientVertex = "+ orientVertex)
graph.commit()
println("AFTER orientVertex = "+ orientVertex)
I get debug printouts as
ODocument = {phoneNumber:45435345,email:moses#email.com,dateOfBirth:-766198800000,lastName:Johnson,firstName:Moses,avatarURL:null,loginInfo:{providerID:credentials,providerKey:moses#email.com},userID:a8d96be9-1d09-4e8f-bf8d-6a0d32e1e5aa}
BEFORE orientVertex = v(null)[#3:-2]
AFTER orientVertex = v(null)[#3:4]
As you can see, the vertex is null. Nothing is persisted. I get an ORID that changes the cluster position number.
When I repeat the save the cluster position number is incremented
BEFORE orientVertex = v(null)[#3:-3]
AFTER orientVertex = v(null)[#3:7]
Why does this happen and how can I fix this please? There are no exceptions so i cant tell whats wrong. The cluster/table for User exists on the DB with all teh right fields.
I am using orientdb-community-2.2.0 and Scala.
regards
Sorted it out at last. I was instantiating the ODocument without the class name. In
UserEntityMapper.toODocument(user)
I was doing the equivalent of this
new ODocument(Map("name"->"john", "city" -> "London"))
instead of this
new ODocument("User").fromMap(Map("name"->"john", "city" -> "London"))
So the DB did not pick up the User class.
Thanks actual for pointing me in the right direction

many to many relation gorm table

I have a little problem filtering data...I have a relation many to many.
Sponsor and Old
I have one intermediary table with both ids...
When I log in, my session save a Sponsor id...but when I go to see Old view, appears every Olds... How to access the intermediary table from the OldController or the SponsorController?
In my Oldcontroller I have:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
def sponsor = Sponsor.findById(session.getAttribute("id"))
def myOld = Old.findAllBySponsor(sponsor, params)
def allMyOld = Old.findAllBySponsor(sponsor)
respond myOld, model:[oldInstanceCount: allMyOld.size()]
//respond Old.list(params), model:[oldInstanceCount: Old.count()]
}
But returns unexpected NullpointerException when processing request: [GET] /oldCare/old/index
No value specified for parameter 2.. Stacktrace follows:
Message: No value specified for parameter 2.
How I access the intermediary table for filtering the olds and appears just the Old associated a one Sponsor?
Assuming you have the following :
class Old {
String title
static hasMany = [sponsours: Sponsour]
}
class Sponsour {
String name
static hasMany = [olds:Old]
}
To find :
def sponsor = Sponsor.load(session.getAttribute("id"))
def allMyOlds = Old.findBySponsour(sponsor,params)