Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty datacenter name causes table create to fail #131

Closed
jchannon opened this issue Sep 18, 2013 · 13 comments
Closed

Empty datacenter name causes table create to fail #131

jchannon opened this issue Sep 18, 2013 · 13 comments

Comments

@jchannon
Copy link

As you can probably tell, I'm completely new to Rethink and am using the node.js API docs to udnerstand it.

I have the below but it fails saying the db name is "" when it tries to do the connection.Run(addTable);


var connection = ConfigConnectionFactory.Instance.Get("testCluster");
connection.Connect();
var result = connection.Run(Query.DbList());
foreach (var s in result)
{
   connection.Run(Query.DbDrop(s));
}
var res = connection.Run(Query.DbCreate("movies"));

var addTable = new RethinkDb.QueryTerm.TableCreateQuery(new DbQuery("movies"), "movies", "", "Id", 4096);
connection.Run(addTable);
var insert = new InsertQuery<Movie>(new TableQuery<Movie>(new DbQuery("movies"), "movies", false), new[] { new Movie() { Name = "300" }, new Movie() { Name = "21" } }, false);
connection.Run(insert);
@karlgrz
Copy link
Collaborator

karlgrz commented Sep 18, 2013

No worries at all, glad to help out! I just got off the train, I'll be at
the office in about 20 minutes I'll try to run the code you have here.
On Sep 18, 2013 8:36 AM, "Jonathan Channon" notifications@github.com
wrote:

As you can probably tell, I'm completely new to Rethink and am using the
node.js API docs to udnerstand it.

I have the below but it fails saying the db name is "" when it tries to do
the connection.Run(addTable);

var connection = ConfigConnectionFactory.Instance.Get("testCluster");
connection.Connect();
var result = connection.Run(Query.DbList());
foreach (var s in result)
{
connection.Run(Query.DbDrop(s));
}
var res = connection.Run(Query.DbCreate("movies"));

var addTable = new RethinkDb.QueryTerm.TableCreateQuery(new DbQuery("movies"), "movies", "", "Id", 4096);
connection.Run(addTable);
var insert = new InsertQuery(new TableQuery(new DbQuery("movies"), "movies", false), new[] { new Movie() { Name = "300" }, new Movie() { Name = "21" } }, false);
connection.Run(insert);


Reply to this email directly or view it on GitHubhttps://github.com//issues/131
.

@karlgrz
Copy link
Collaborator

karlgrz commented Sep 18, 2013

I am seeing issues as well when using connection.Run instead of connection.RunAsync:

System.AggregateException was unhandled
  HResult=-2146233088
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at RethinkDb.TaskUtilities.ExecuteSynchronously[T](Func`1 taskDelegate) in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\TaskUtilities.cs:line 49
       at RethinkDb.Connection.Run[TResponseType](IWriteQuery`1 queryObject) in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\Connection.cs:line 669
       at rethinkdb_net.runner.Program.Main(String[] args) in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net.runner\Program.cs:line 22
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: RethinkDb.RethinkDbRuntimeException
       HResult=-2146233088
       Message=Runtime error: Database name `` invalid (Use A-Za-z0-9_ only).
       Source=RethinkDb
       StackTrace:
            at RethinkDb.Connection.<RunAsync>d__45`1.MoveNext() in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\Connection.cs:line 432
       InnerException: 

And here's the inner exception detail/stacktrace:

Runtime error: Database name `` invalid (Use A-Za-z0-9_ only).
 at RethinkDb.Connection.<RunAsync>d__45`1.MoveNext() in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\Connection.cs:line 432

Here's the code I used (slightly modified to add a basic Movie class:

using System.Runtime.Serialization;
using RethinkDb;
using RethinkDb.Configuration;
using RethinkDb.QueryTerm;

namespace rethinkdb_net.runner
{
    class Program
    {
        static void Main(string[] args)
        {
            var connection = ConfigConnectionFactory.Instance.Get("testCluster");
            connection.Connect();
            var result = connection.Run(Query.DbList());
            foreach (var s in result)
            {
                connection.Run(Query.DbDrop(s));
            }
            var res = connection.Run(Query.DbCreate("movies"));

            var addTable = new RethinkDb.QueryTerm.TableCreateQuery(new DbQuery("movies"), "movies", "", "Id", 4096);
            connection.Run(addTable);
            var insert = new InsertQuery<Movie>(new TableQuery<Movie>(new DbQuery("movies"), "movies", false), new[] { new Movie() { Name = "300" }, new Movie() { Name = "21" } }, false);
            connection.Run(insert);
        }
    }

    [DataContract]
    public class Movie
    {
        [DataMember]
        public string Name;
    }
}

Thanks for pointing this out, @jchannon. @mfenniak later on in the day I will try to dive into this a bit more, I need to get to work right now.

@jchannon
Copy link
Author

Glad its not just me. Is that the correct API to use when adding data? I know its always an issue on OSS to get docs written

@karlgrz
Copy link
Collaborator

karlgrz commented Sep 18, 2013

Take a look at this test: https://github.com/mfenniak/rethinkdb-net/blob/master/rethinkdb-net-test/Integration/TableTests.cs#L23

(sorry for the long link, not sure if there's a better way to link to source code lines within github)

Typically create a reference to a Table object:

testTable = Query.Db("test").Table<TestObject>("table");

Then call Insert method and pass it an object, like this line: https://github.com/mfenniak/rethinkdb-net/blob/master/rethinkdb-net-test/Integration/TableTests.cs#L71-L86

var obj = new TestObject()
{
     Name = "Jim Brown",
     Children = new TestObject[] {
     new TestObject() { Name = "Scan" }
     }
};
var resp = await connection.RunAsync(testTable.Insert(obj));

That being said, your call should work, I would imagine.

@jchannon
Copy link
Author

Cool, thanks.

Is there a need to use Query.Db("test")?

I see node.js allows you to setup a default db that it uses but this is where maybe the libs diverge.

@karlgrz
Copy link
Collaborator

karlgrz commented Sep 18, 2013

"test" database is created on a new install of rethinkdb (AFAIK).

It's just something to use for, testing :-)

We use it in the integration tests on the CI server. It's just another
database.

On Wed, Sep 18, 2013 at 10:11 AM, Jonathan Channon <notifications@github.com

wrote:

Cool, thanks.

Is there a need to use Query.Db("test")?

I see node.js allows you to setup a default db that it uses but this is
where maybe the libs diverge.


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-24671897
.

@jchannon
Copy link
Author

Sorry I meant the need to specify the database on every call

@karlgrz
Copy link
Collaborator

karlgrz commented Sep 18, 2013

No worries.

If you use that reference style that I linked to then no, you won't need to
specify it every time since you specify it when making the reference. It's
the same in the python and javascript clients, as well (I haven't used ruby
or node.js too much, although node.js is pretty much just javascript so I'd
assume it's similar as well).

On Wed, Sep 18, 2013 at 10:15 AM, Jonathan Channon <notifications@github.com

wrote:

Sorry I meant the need to specify the database on every call


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-24672310
.

@dragan
Copy link
Collaborator

dragan commented Sep 18, 2013

@jchannon Until we get some documentation in place, browsing the tests is a good resource on how to use the API.

@jchannon
Copy link
Author

Understood

@mfenniak
Copy link
Owner

You can store an instance of the Query.Db("...").Table("....") queries in a variable, field, or static field to reduce the amount of references you need to make these queries.

Note that this might just conflict with what I said in the other issue about not referencing the QueryTerm namespace directly, since your variables might need those types. I'd consider that a bug in the API design; I'd eventually replace those direct references with interfaces. 😀

@mfenniak
Copy link
Owner

The error:

Runtime error: Database name `` invalid (Use A-Za-z0-9_ only).
 at RethinkDb.Connection.<RunAsync>d__45`1.MoveNext() in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\Connection.cs:line 432

is caused by using an empty string as the datacenter name in the TableCreate query. The error is misleading as it describes the "Database name" as being invalid, but that's the error we're getting back from RethinkDB. If you change out the "" parameter for null, or use Query.Db(...).TableCreate(...) use the default value of null, this error goes away.

We could validate this client-side before issuing our query... but we don't do any validation along those lines so far. Or, we could treat nulls and empty strings as equivalent in our null-check in TableCreateQuery.cs.

@karlgrz
Copy link
Collaborator

karlgrz commented Sep 19, 2013

Ahhh, good catch, @mfenniak.

On Wed, Sep 18, 2013 at 8:45 PM, Mathieu Fenniak
notifications@github.comwrote:

The error:

Runtime error: Database name ``invalid (Use A-Za-z0-9_ only).
at RethinkDb.Connection.d__45`1.MoveNext() in c:\Users\Karl\Downloads\rethinkdb-net-master\rethinkdb-net-master\rethinkdb-net\Connection.cs:line 432

is caused by using an empty string as the datacenter name in the
TableCreate query. The error is misleading as it describes the "Database
name" as being invalid, but that's the error we're getting back from
RethinkDB. If you change out the "" parameter for null, or use
Query.Db(...).TableCreate(...) use the default value of null, this error
goes away.

We could validate this client-side before issuing our query... but we
don't do any validation along those lines so far. Or, we could treat nulls
and empty strings as equivalent in our null-check in TableCreateQuery.cs.


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-24712396
.

mfenniak added a commit that referenced this issue Sep 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants