public String readSchemaFile(String path) { try { return JavaResourceUtil.readTextFromResource("schemas/" + path); } catch (IOException e) { throw new TajoInternalError(e); } }
@Before public void setUp() throws Exception { schemaUrl = JavaResourceUtil.getResourceURL("dataset/testVariousTypes.avsc"); assertNotNull(schemaUrl); File file = new File(schemaUrl.getPath()); assertTrue(file.exists()); expected = new Schema.Parser().parse(file); }
@Test public void testByteBufLineReaderWithoutTerminating() throws IOException { String path = JavaResourceUtil.getResourceURL("dataset/testLineText.txt").getFile(); File file = new File(path); String data = FileUtil.readTextFile(file); ByteBufInputChannel channel = new ByteBufInputChannel(new FileInputStream(file)); ByteBufLineReader reader = new ByteBufLineReader(channel); long totalRead = 0; int i = 0; AtomicInteger bytes = new AtomicInteger(); for(;;){ ByteBuf buf = reader.readLineBuf(bytes); totalRead += bytes.get(); if(buf == null) break; i++; } IOUtils.cleanup(null, reader); assertFalse(channel.isOpen()); assertEquals(file.length(), totalRead); assertEquals(file.length(), reader.readBytes()); assertEquals(data.split("\n").length, i); }
private JSONObject loadFromConfig(String fileName) { String json; try { json = JavaResourceUtil.readTextFromResource(fileName); } catch (FileNotFoundException fnfe) { return null; } catch (IOException e) { throw new RuntimeException(e); } return parseJson(json); }
String path = JavaResourceUtil.getResourceURL("dataset/testVariousTypes.avsc").toString(); meta.putProperty(StorageConstants.AVRO_SCHEMA_URL, path);
private JSONObject loadFromConfig(String fileName) { String json; try { json = JavaResourceUtil.readTextFromResource(fileName); } catch (FileNotFoundException fnfe) { return null; } catch (IOException e) { throw new RuntimeException(e); } return parseJson(json); }
public String readSchemaFile(String path) { try { return JavaResourceUtil.readTextFromResource("schemas/" + path); } catch (IOException e) { throw new TajoInternalError(e); } }
private void storeTableContents(String resource, Path path) throws IOException { String csvTable = JavaResourceUtil.readTextFromResource(resource); String fixedCsvTable = fixExtraColumn(csvTable); FileUtil.writeTextToFile(fixedCsvTable, path); }
@Test public void testBuildDDLForBaseTable() throws Exception { TableDesc desc = new TableDesc("db1.table2", schema1, meta1, new Path("/table1").toUri()); assertEquals(JavaResourceUtil.readTextFromResource("results/testDDLBuilder/testBuildDDLForBaseTable.result"), DDLBuilder.buildDDLForBaseTable(desc)); }
private void loadTPCHTables() throws SQLException, IOException { try (Connection connection = DriverManager.getConnection(getJdbcUrlForAdmin(), "postgres", null)) { connection.setCatalog("tpch"); try (Statement statement = connection.createStatement()) { for (String tableName : TPCH_TABLES) { String sql = JavaResourceUtil.readTextFromResource("pgsql/" + tableName + ".sql"); statement.executeUpdate(sql); // restore the table contents into a file stored in a local file system for PgSQL COPY command String path = restoreTableContents(tableName); String copyCommand = genLoadStatement(tableName, path); statement.executeUpdate(copyCommand); } // load DATETIME_TYPES table String sql = JavaResourceUtil.readTextFromResource("pgsql/datetime_types.sql"); statement.executeUpdate(sql); Path filePath = new Path(testPath, "datetime_types.txt"); storeTableContents("pgsql/datetime_types.txt", filePath); String copyCommand = genLoadStatement("datetime_types", filePath.toUri().getPath()); LOG.info(copyCommand); statement.executeUpdate(copyCommand); } catch (Throwable t) { t.printStackTrace(); throw t; } } }
private TpchTestBase() throws IOException { names = new String[] {"customer", "lineitem", "nation", "orders", "part", "partsupp", "region", "supplier", "small_supplier", "empty_orders"}; paths = new String[names.length]; for (int i = 0; i < names.length; i++) { nameMap.put(names[i], i); } tpch = new TPCH(); tpch.loadSchemas(); tpch.loadQueries(); schemas = new Schema[names.length]; for (int i = 0; i < names.length; i++) { schemas[i] = tpch.getSchema(names[i]); } // create a temporal table File tpchTablesDir = new File(new File(CommonTestingUtil.getTestDir().toUri()), "tpch"); for (int i = 0; i < names.length; i++) { String str = JavaResourceUtil.readTextFromResource("tpch/" + names[i] + ".tbl"); Path tablePath = new Path(new Path(tpchTablesDir.toURI()), names[i] + ".tbl"); FileUtil.writeTextToFile(str, tablePath); paths[i] = tablePath.toString(); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } }
@Test public void testBuildDDLForExternalTable() throws Exception { TableDesc desc = new TableDesc("db1.table1", schema1, meta1, new Path("/table1").toUri()); desc.setPartitionMethod(partitionMethod1); desc.setExternal(true); assertEquals(JavaResourceUtil.readTextFromResource("results/testDDLBuilder/testBuildDDLForExternalTable.result"), DDLBuilder.buildDDLForExternalTable(desc)); }
/** * In order to add more unit tests, please add SQL files into resources/queries/TestSQLAnalyzer/errors. * This test just checkes if the error messages caused by SQL parsing errors * * @throws IOException * @throws URISyntaxException */ @Test public void testErrorMessages() throws IOException, URISyntaxException { for (Pair<String, String> pair : getFileContents("errors")) { String fileName = pair.getFirst().split("\\.")[0]; String expectedResult = ""; try { expectedResult = JavaResourceUtil.readTextFromResource("results/TestSQLAnalyzer/errors/" + fileName + ".result"); } catch (FileNotFoundException fnfe) { } try { Expr expr = parseQuery(pair.getSecond()); System.out.println(expr); fail(pair.getFirst() + " must be failed."); } catch (SQLSyntaxError e) { assertEquals("Error message is different from " + fileName + ".result", expectedResult, e.getMessage()); } System.out.println(pair.getFirst() + " test passed..."); } System.out.flush(); }
try { fileName = pair.getFirst().split("\\.")[0]; expectedResult = JavaResourceUtil.readTextFromResource("results/TestSQLAnalyzer/" + fileName + ".result"); } catch (FileNotFoundException ioe) { expectedResult = "";
@Test public void testBuildDDLQuotedTableName() throws Exception { Schema schema2 = SchemaBuilder.builder() .add("name", TajoDataTypes.Type.BLOB) .add("addr", TajoDataTypes.Type.TEXT) .add("FirstName", TajoDataTypes.Type.TEXT) .add("LastName", TajoDataTypes.Type.TEXT) .add("with", TajoDataTypes.Type.TEXT) .build(); Schema expressionSchema2 = SchemaBuilder.builder() .add("BirthYear", TajoDataTypes.Type.INT4) .build(); PartitionMethodDesc partitionMethod2 = new PartitionMethodDesc( "db1", "table1", CatalogProtos.PartitionType.COLUMN, "key,key2", expressionSchema2); TableDesc desc = new TableDesc("db1.TABLE2", schema2, meta1, new Path("/table1").toUri()); desc.setPartitionMethod(partitionMethod2); desc.setExternal(true); assertEquals(JavaResourceUtil.readTextFromResource("results/testDDLBuilder/testBuildDDLQuotedTableName1.result"), DDLBuilder.buildDDLForExternalTable(desc)); desc = new TableDesc("db1.TABLE1", schema2, meta1, new Path("/table1").toUri()); desc.setPartitionMethod(partitionMethod2); desc.setExternal(false); assertEquals(JavaResourceUtil.readTextFromResource("results/testDDLBuilder/testBuildDDLQuotedTableName2.result"), DDLBuilder.buildDDLForBaseTable(desc)); }
Schema schema = table.getLogicalSchema(); String[] rows = JavaResourceUtil.readTextFromResource("tpch/" + tableName + ".tbl").split("\n");