@Override public void setValue(UserSession session, String value) { session.defaultSchemaPath = Strings.isNullOrEmpty(value) ? null : new NamespaceKey(SqlUtils.parseSchemaPath(value)); } },
@Test public void testParseSchemaPath() { assertEquals(asList("a", "b", "c"), SqlUtils.parseSchemaPath("a.b.c")); assertEquals(asList("a"), SqlUtils.parseSchemaPath("a")); assertEquals(asList("a", "b.c", "d"), SqlUtils.parseSchemaPath("a.\"b.c\".d")); assertEquals(asList("a", "c"), SqlUtils.parseSchemaPath("a..c")); } }
private void assertFoldersExist(List<String> expFolders) throws Exception { for (String folderPath : expFolders) { NamespaceKey folderKey = new NamespaceKey(SqlUtils.parseSchemaPath(folderPath)); namespaceService.getFolder(folderKey); // if the folder doesn't exit we get an exception } }
private void assertFoldersDoNotExist(List<String> expFolders) throws Exception { for (String folderPath : expFolders) { NamespaceKey folderKey = new NamespaceKey(SqlUtils.parseSchemaPath(folderPath)); try { namespaceService.getFolder(folderKey); // if the folder doesn't exit we get an exception fail(); } catch (NamespaceNotFoundException ex) { /* no-op */ } } }
@Override public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception { final SqlUseSchema useSchema = SqlNodeUtil.unwrap(sqlNode, SqlUseSchema.class); // first we try locally. NamespaceKey orig = new NamespaceKey(useSchema.getSchema()); NamespaceKey defaultPath = catalog.resolveToDefault(orig); NamespaceKey compoundPath = orig.size() == 1 && orig.getRoot().contains(".") ? new NamespaceKey(SqlUtils.parseSchemaPath(orig.getRoot())) : null; if(defaultPath != null && catalog.containerExists(defaultPath)) { session.setDefaultSchemaPath(defaultPath.getPathComponents()); } else if (catalog.containerExists(orig)) { session.setDefaultSchemaPath(orig.getPathComponents()); } else if(compoundPath != null && catalog.containerExists(compoundPath)) { // kept to support old compound use statements. session.setDefaultSchemaPath(compoundPath.getPathComponents()); } else { throw UserException.validationError().message("Schema [%s] is not valid with respect to either root schema or current default schema.", orig).build(logger); } return Collections.singletonList(SimpleCommandResult.successful("Default schema changed to [%s]", session.getDefaultSchemaPath())); } }
private static SourceTableDefinition newDataset(final String dsPath) { final List<String> path = SqlUtils.parseSchemaPath(dsPath); SourceTableDefinition ret = mock(SourceTableDefinition.class); NamespaceKey datasetName = new NamespaceKey(path); when(ret.getName()).thenReturn(datasetName); BatchSchema schema = BatchSchema.newBuilder() .addField(new Field("string", FieldType.nullable(ArrowType.Utf8.INSTANCE), null)) .build(); DatasetConfig dsConfig = new DatasetConfig() .setName(Util.last(path)) .setFullPathList(path) .setType(DatasetType.PHYSICAL_DATASET_SOURCE_FILE) .setRecordSchema(ByteString.EMPTY) .setPhysicalDataset( new PhysicalDataset() .setFormatSettings(null)) .setSchemaVersion(DatasetHelper.CURRENT_VERSION) .setRecordSchema(schema.toByteString()) .setReadDefinition(new ReadDefinition()); try { when(ret.getDataset()).thenReturn(dsConfig); } catch (Exception ignored) { } when(ret.getType()).thenReturn(DatasetType.PHYSICAL_DATASET_SOURCE_FILE); when(ret.isSaveable()).thenReturn(true); return ret; }