chapeldev/cdo

Cannot declare associative array in PgConnection Class

Closed this issue ยท 12 comments

I am experimenting a crazy behavior of the compiler when I declare I associative array in the PgConnection class.

When I declare this associative array, the compiler says that the domain of an associative array of another class (the Row class) cannot be found.

Here is the declaration of problematic associative array:
https://github.com/marcoscleison/cdo/blob/00340eefd1abe2a78c89bef655d2b4a9bf0ecd9a/src/Postgres.chpl#L37

Here is the output:

./src/Cdo.chpl:453: error: unable to resolve type

The declaration indicated by the compiler is:
https://github.com/marcoscleison/cdo/blob/00340eefd1abe2a78c89bef655d2b4a9bf0ecd9a/src/Cdo.chpl#L453

When I comment the declaration, everything goes on. How to solve this.

the domain of an associative array of another class (the Row class) cannot be found.

Can you clarify this part? The parts of code that were linked are only associative arrays of strings. Maybe I'm looking at the wrong parts...

Have you been able to reproduce the error for a smaller test? That would help me track things down quicker.

Stop stalling Ben, just fix it already...

@ben-albrecht , thank you for your great attention.
This issue is hard for me. I will try to explain the problems that I am experimenting:

I have PgConnection class. I would like to declare an associative map in this class. But when I declare it, the compiler says that a type was not found in another class (Row class). When I cut off the associative declaration from PgConnection, the compiler becomes happy.

I did not open an issue in the Chapel project because I want to be sure that It is not my code mistake.
Until now, I did not see what is wrong with my code. Due to family problems, I stayed far from the code. I came now and even with this, I cannot see what I did wrong.

Thanks.

Here is an example chapel program to attempt to read an array from Postgres. I hope it helps

use Postgres;

config const DB_HOST: string = "localhost";
config const DB_USER: string = "buddha";
config const DB_NAME: string = "buddha";
config const DB_PWD: string = "buddha";

writeln("aaaaggghhhh!");

/*

DROP TABLE IF EXISTS aagg;
CREATE TABLE aagg (team text, name text);
INSERT INTO aagg VALUES ('Wonder Pets', 'Linny'); 
INSERT INTO aagg VALUES ('Wonder Pets', 'Ming Ming');
INSERT INTO aagg VALUES ('Wonder Pets', 'Tuck');
INSERT INTO aagg VALUES ('OJ Defense Team', 'F. Lee Bailey'); 
INSERT INTO aagg VALUES ('OJ Defense Team', 'Robert Shapiro');
INSERT INTO aagg VALUES ('OJ Defense Team', 'Johnny Cohchran');

 */

 

var con = PgConnectionFactory(host=DB_HOST, user=DB_USER, database=DB_NAME, passwd=DB_PWD);
var cursor = con.cursor();
// Retrieve the data
const q = "SELECT team, array_agg(name) AS members FROM aagg GROUP BY team;"; 
cursor.query(q);

for row in cursor {
  writeln("Team: ", row['name'], "\tMembers: ", row['members'] );
  for member in row['members'] {
    writeln ("Special mention to ", member);
  }
}

I have not yet checked if the usage fits your example.

@marcoscleison - started looking into this again, and @buddha314 informed me that you may have a work-around in place. Is this still something you need support on? (sorry to drag it out!)

@ben-albrecht , thank you very much for the attention. I solved the issue related to the Postgres array in Chapel.

  1. When I put an associative array in PgConnection, it triggers an error in other classes that have an associative array.
    2)I think that it is a Compile issue and not coding one.
  2. I declared the associative array that I needed in another class and reached the solution.

This are my mainpoints.

I will close this one, but I will think about open an issue on chapel github. I will investigate the reproductivity of the issue at another code.

@ben-albrecht and @buddha314, I reopened this issue because I am struggling with a compiler error. I am suffering to describe this issue because of the strangeness of it and my cultural difference (English is not my mother tongue). I need your help!

The first time I experimented this issue was when I declared an associative array in PgConnection class. The compiler trigged an error saying that "error: unable to resolve type". I verified the line that the compiler indicated. It was the first declaration of an associative array in Row class in Cdo.chpl.
I moved the associative array declaration from PgConnection class to PgCursor and the compiler became happy compiling all Postgres based examples properly.
Now, I am porting Model features for Mysql driver. The error came again. Now the error triggers when I use the method "table" of MysqlConnection class.
In the example I use this statement:

https://github.com/marcoscleison/cdo/blob/f7e3da8d9c2801aeecf4d8a07a2ccad95dbada6c/examples/query_builder_mysql_ex.chpl#L10

This method is implemented in MySql Connection at line:
https://github.com/marcoscleison/cdo/blob/f7e3da8d9c2801aeecf4d8a07a2ccad95dbada6c/src/Mysql.chpl#L127

The method returns a forwarded class with implementation in Mysql.chpl:
https://github.com/marcoscleison/cdo/blob/f7e3da8d9c2801aeecf4d8a07a2ccad95dbada6c/src/Mysql.chpl#L449

It triggers error even if the class is void with default methods.

The compiler always indicates that the "error: unable to resolve type" is the first declaration of domain related to an associative array in the class Row:

https://github.com/marcoscleison/cdo/blob/f7e3da8d9c2801aeecf4d8a07a2ccad95dbada6c/src/Cdo.chpl#L310

The Postgres driver compiles without error unless I declare an associative array in PgConnection.
Mysql driver compiles well unless I call table method in MysqlConnection.

I strongly suspect that it is a compiler issue, but I am not finding words to explain it.

Alright. I'll take a look into it.

I've opened an issue for the strange behavior. Until it's resolved, you should be able to work around this by removing the type of the argument in proc this() for CursorBase:

  proc this(idx:int):Row { }

->

  proc this(idx):Row { }

Hi,
getting out the type, it compiled.
I will explore more. But things are going.

I will close this when have sure everything is ok.
Thanks.

I think that I can close it because I am reaching the compilation.
Thanks!