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

Provide an API to interact with a table schema descriptor - fieldNames, primaryKey etc properties? #6

Closed
georgeslabreche opened this issue Oct 9, 2017 · 1 comment
Labels

Comments

@georgeslabreche
Copy link

No description provided.

@georgeslabreche
Copy link
Author

georgeslabreche commented Oct 10, 2017

@pwalsh:

  1. Implemented getter for field names.
  2. Implemented getter and setter for primary key.
  3. Implemented primary key parser when loading schema from file or JSON object.

Test cases here:

@Test
public void testCreateSchemaFromFileWithValidPrimaryKey() throws Exception{
String sourceFileAbsPath = TableTest.class.getResource("/fixtures/simple_schema_with_valid_pk.json").getPath();
Schema schemaWithValidPK = new Schema(sourceFileAbsPath);
Assert.assertEquals("id", schemaWithValidPK.getPrimaryKey());
}
@Test
public void testCreateSchemaFromFileWithInvalidPrimaryKey() throws Exception{
String sourceFileAbsPath = TableTest.class.getResource("/fixtures/simple_schema_with_invalid_pk.json").getPath();
exception.expect(PrimaryKeyException.class);
Schema schemaWithInvalidPK = new Schema(sourceFileAbsPath);
}
@Test
public void testCreateSchemaFromFileWithValidCompositeKey() throws Exception{
String sourceFileAbsPath = TableTest.class.getResource("/fixtures/simple_schema_with_valid_ck.json").getPath();
Schema schemaWithValidCK = new Schema(sourceFileAbsPath);
Assert.assertArrayEquals(new String[]{"name", "surname"}, schemaWithValidCK.getPrimaryKey());
}
@Test
public void testCreateSchemaFromFileWithInvalidCompositeKey() throws Exception{
String sourceFileAbsPath = TableTest.class.getResource("/fixtures/simple_schema_with_invalid_ck.json").getPath();
exception.expect(PrimaryKeyException.class);
Schema schemaWithInvalidCK = new Schema(sourceFileAbsPath);
}

And here:

@Test
public void testSinglePrimaryKey() throws PrimaryKeyException{
Schema schema = new Schema();
Field idField = new Field("id", Field.FIELD_TYPE_INTEGER);
schema.addField(idField);
schema.setPrimaryKey("id");
String key = schema.getPrimaryKey();
Assert.assertEquals("id", key);
}
@Test
public void testInvalidSinglePrimaryKey() throws PrimaryKeyException{
Schema schema = new Schema();
Field idField = new Field("id", Field.FIELD_TYPE_INTEGER);
schema.addField(idField);
exception.expect(PrimaryKeyException.class);
schema.setPrimaryKey("invalid");
}
@Test
public void testCompositePrimaryKey() throws PrimaryKeyException{
Schema schema = new Schema();
Field idField = new Field("id", Field.FIELD_TYPE_INTEGER);
schema.addField(idField);
Field nameField = new Field("name", Field.FIELD_TYPE_STRING);
schema.addField(nameField);
Field surnameField = new Field("surname", Field.FIELD_TYPE_STRING);
schema.addField(surnameField);
schema.setPrimaryKey(new String[]{"name", "surname"});
String[] compositeKey = schema.getPrimaryKey();
Assert.assertEquals("name", compositeKey[0]);
Assert.assertEquals("surname", compositeKey[1]);
}
@Test
public void testInvalidCompositePrimaryKey() throws PrimaryKeyException{
Schema schema = new Schema();
Field idField = new Field("id", Field.FIELD_TYPE_INTEGER);
schema.addField(idField);
Field nameField = new Field("name", Field.FIELD_TYPE_STRING);
schema.addField(nameField);
Field surnameField = new Field("surname", Field.FIELD_TYPE_STRING);
schema.addField(surnameField);
exception.expect(PrimaryKeyException.class);
schema.setPrimaryKey(new String[]{"name", "invalid"});
}

Foreign Key parsing, getting, and setting has not been implemented. Created Issue #12 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant