reset password
Author Message
xytian
Posts: 70
Posted 03:20 Nov 11, 2013 |

I ran CreateStudentDB.java to create the test data, the table DEPT was created with statement "create table DEPT(DId int, DName varchar(8))", however, when I do the query, the output is always like this, no matter what column order I specified. It seems the field order was changed in the schema, but the order matters for the insert statement

SQL> select did, dname from dept

   dname   did
--------------
 compsci    10
    math    20
   drama    30
 

Last edited by xytian at 03:36 Nov 11, 2013.
cysun
Posts: 2935
Posted 08:33 Nov 11, 2013 |

The problem is in the Schema class, which uses a HashMap to store the fields, and HashMap does not preserve the insertion-order.

Schema is also used in ProjectPlan, which is why the query result columns are not in the order specified in the query.

I would consider this a bug, though it's possible that it's intentionally implemented this way as an exercise for the students. Changing the HashMap to some order-preserving data structure like List or LinkedHashMap should fix the problem. LinkedHashMap is probably easier since it's still a Map so you don't need to change anything else.

xytian
Posts: 70
Posted 08:57 Nov 11, 2013 |

 This doesn't look like a trivial job. I changed HashMap to LinkedHashMap, there is no error on schema.java, but the server won't start.

Exception in thread "main" java.lang.NullPointerException
    at simpledb.record.TableInfo.offset(TableInfo.java:78)
    at simpledb.record.RecordPage.fieldpos(RecordPage.java:144)
    at simpledb.record.RecordPage.getString(RecordPage.java:70)
    at simpledb.record.RecordFile.getString(RecordFile.java:81)
    at simpledb.metadata.StatMgr.refreshStatistics(StatMgr.java:56)
    at simpledb.metadata.StatMgr.<init>(StatMgr.java:28)
    at simpledb.metadata.MetadataMgr.<init>(MetadataMgr.java:16)
    at simpledb.server.SimpleDB.initMetadataMgr(SimpleDB.java:90)
    at simpledb.server.SimpleDB.init(SimpleDB.java:49)
    at simpledb.server.Startup.main(Startup.java:10)

cysun
Posts: 2935
Posted 09:33 Nov 11, 2013 |
megtian wrote:

 This doesn't look like a trivial job. I changed HashMap to LinkedHashMap, there is no error on schema.java, but the server won't start.

Exception in thread "main" java.lang.NullPointerException
    at simpledb.record.TableInfo.offset(TableInfo.java:78)
    at simpledb.record.RecordPage.fieldpos(RecordPage.java:144)
    at simpledb.record.RecordPage.getString(RecordPage.java:70)
    at simpledb.record.RecordFile.getString(RecordFile.java:81)
    at simpledb.metadata.StatMgr.refreshStatistics(StatMgr.java:56)
    at simpledb.metadata.StatMgr.<init>(StatMgr.java:28)
    at simpledb.metadata.MetadataMgr.<init>(MetadataMgr.java:16)
    at simpledb.server.SimpleDB.initMetadataMgr(SimpleDB.java:90)
    at simpledb.server.SimpleDB.init(SimpleDB.java:49)
    at simpledb.server.Startup.main(Startup.java:10)

I think that's because your previous StudentDB was created with HashMap so it had a different field order. Just stop the SimpleDB server, delete the StudentDB folder under $USER, then try again.

xytian
Posts: 70
Posted 09:36 Nov 11, 2013 |

it works, thank you

Last edited by xytian at 09:36 Nov 11, 2013.
xytian
Posts: 70
Posted 17:53 Nov 11, 2013 |

When we open a new transaction, should we always have a commit() in the end?

After we made the SimpleDB support ">" and "<", do we need to consider the change in the reductionFactor?

Last edited by xytian at 17:55 Nov 11, 2013.
cysun
Posts: 2935
Posted 18:58 Nov 11, 2013 |
megtian wrote:

When we open a new transaction, should we always have a commit() in the end?

After we made the SimpleDB support ">" and "<", do we need to consider the change in the reductionFactor?

Yes, though I don't think you need to add code to open/close transactions in this exercise.

And no, you don't need to worry about reductionFactor. It's for query optimization, which we won't cover in this class.

xytian
Posts: 70
Posted 19:11 Nov 11, 2013 |

I did use a transaction, in getTableInfo(tbl, tx)  in order to get the schema. Is there a better way?

cysun wrote:

Yes, though I don't think you need to add code to open/close transactions in this exercise.

 

cysun
Posts: 2935
Posted 20:29 Nov 11, 2013 |
megtian wrote:

I did use a transaction, in getTableInfo(tbl, tx)  in order to get the schema. Is there a better way?

cysun wrote:

Yes, though I don't think you need to add code to open/close transactions in this exercise.

Maybe.

xytian
Posts: 70
Posted 13:50 Nov 12, 2013 |

I see, it's about where to populate the field list