-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for data template schema field string literals in PDL
Encode the SCHEMA field in generated data templates according to the file format of the source schema file. Postponing the use of a new interface for files generated from PDSC to avoid build failures, with the expectation that this will be addressed relatively soon. RB=1864201 G=sf-reviewers R=ybi,kbalasub,mnchen A=ybi,kbalasub
- Loading branch information
Showing
17 changed files
with
476 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
28.0.6 | ||
------ | ||
(RB=1864201) | ||
Support for data template schema field string literals in PDL | ||
|
||
28.0.5 | ||
------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
data/src/main/java/com/linkedin/data/schema/SchemaFormatType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright (c) 2019 LinkedIn Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.linkedin.data.schema; | ||
|
||
import com.linkedin.data.schema.grammar.PdlSchemaParserFactory; | ||
|
||
|
||
/** | ||
* Representation of a particular schema format type. | ||
* | ||
* @author Evan Williams | ||
*/ | ||
public enum SchemaFormatType | ||
{ | ||
PDSC(SchemaParserFactory.instance()), | ||
PDL(PdlSchemaParserFactory.instance()); | ||
|
||
SchemaFormatType(DataSchemaParserFactory schemaParserFactory) | ||
{ | ||
_schemaParserFactory = schemaParserFactory; | ||
} | ||
|
||
private final DataSchemaParserFactory _schemaParserFactory; | ||
|
||
public DataSchemaParserFactory getSchemaParserFactory() | ||
{ | ||
return _schemaParserFactory; | ||
} | ||
|
||
/** | ||
* Determines the schema format type corresponding with a given filename, or null if it's indeterminable. | ||
* | ||
* @param filename filename | ||
* @return schema format type or null | ||
*/ | ||
public static SchemaFormatType fromFilename(String filename) | ||
{ | ||
if (filename == null) | ||
{ | ||
return null; | ||
} | ||
|
||
final int startIndex = filename.lastIndexOf(".") + 1; | ||
|
||
if (startIndex == filename.length()) | ||
{ | ||
return null; | ||
} | ||
|
||
return fromFileExtension(filename.substring(startIndex)); | ||
} | ||
|
||
/** | ||
* Given some string file extension, determines the schema format type it represents. | ||
* Returns null if the file extension is an unrecognized file extension. | ||
* | ||
* @param fileExtension file extension string | ||
* @return schema format type or null | ||
*/ | ||
public static SchemaFormatType fromFileExtension(String fileExtension) | ||
{ | ||
for (SchemaFormatType fileType : SchemaFormatType.values()) | ||
{ | ||
if (fileType.getSchemaParserFactory().getLanguageExtension().equalsIgnoreCase(fileExtension)) { | ||
return fileType; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
data/src/test/java/com/linkedin/data/schema/TestSchemaFormatType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright (c) 2019 LinkedIn Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.linkedin.data.schema; | ||
|
||
import com.linkedin.data.schema.grammar.PdlSchemaParserFactory; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
/** | ||
* Tests for {@link SchemaFormatType}. | ||
* | ||
* @author Evan Williams | ||
*/ | ||
public class TestSchemaFormatType | ||
{ | ||
@Test | ||
public void testGetSchemaParserFactory() | ||
{ | ||
Assert.assertSame(SchemaFormatType.PDSC.getSchemaParserFactory(), SchemaParserFactory.instance()); | ||
Assert.assertSame(SchemaFormatType.PDL.getSchemaParserFactory(), PdlSchemaParserFactory.instance()); | ||
} | ||
|
||
@Test | ||
public void testFromFilename() | ||
{ | ||
Assert.assertEquals(SchemaFormatType.fromFilename("Foo.pdsc"), SchemaFormatType.PDSC); | ||
Assert.assertEquals(SchemaFormatType.fromFilename("Bar.pdl"), SchemaFormatType.PDL); | ||
Assert.assertEquals(SchemaFormatType.fromFilename("Two.dots.pdsc"), SchemaFormatType.PDSC); | ||
Assert.assertEquals(SchemaFormatType.fromFilename("/some/path/with/Two.dots.pdl"), SchemaFormatType.PDL); | ||
Assert.assertEquals(SchemaFormatType.fromFilename(".pdl"), SchemaFormatType.PDL); | ||
Assert.assertNull(SchemaFormatType.fromFilename("Baz.json")); | ||
Assert.assertNull(SchemaFormatType.fromFilename("Biz")); | ||
Assert.assertNull(SchemaFormatType.fromFilename("Bop.")); | ||
Assert.assertNull(SchemaFormatType.fromFilename(".")); | ||
Assert.assertNull(SchemaFormatType.fromFilename("")); | ||
Assert.assertNull(SchemaFormatType.fromFilename(null)); | ||
} | ||
|
||
@Test | ||
public void testFromFileExtension() | ||
{ | ||
Assert.assertEquals(SchemaFormatType.fromFileExtension("pdsc"), SchemaFormatType.PDSC); | ||
Assert.assertEquals(SchemaFormatType.fromFileExtension("pdl"), SchemaFormatType.PDL); | ||
Assert.assertEquals(SchemaFormatType.fromFileExtension("PdsC"), SchemaFormatType.PDSC); | ||
Assert.assertEquals(SchemaFormatType.fromFileExtension("PDL"), SchemaFormatType.PDL); | ||
Assert.assertNull(SchemaFormatType.fromFileExtension("json")); | ||
Assert.assertNull(SchemaFormatType.fromFileExtension("")); | ||
Assert.assertNull(SchemaFormatType.fromFileExtension(null)); | ||
} | ||
} |
Oops, something went wrong.