public EntityId newMessage() { return new EntityId(); }
public String getId() { return id.getId(); }
private DatasetBuilder(HiveClient client, String user, NamespaceKey datasetPath, boolean ignoreAuthzErrors, StatsEstimationParameters statsParams, HiveConf hiveConf, String dbName, String tableName, Table table, DatasetConfig oldConfig){ if(oldConfig == null){ datasetConfig = new DatasetConfig() .setPhysicalDataset(new PhysicalDataset()) .setId(new EntityId().setId(UUID.randomUUID().toString())); } else { datasetConfig = oldConfig; // We're rewriting the read definition. Delete the old one. oldConfig.setReadDefinition(null); } this.client = client; this.user = user; this.datasetPath = datasetPath; this.hiveConf = hiveConf; this.table = table; this.dbName = dbName; this.tableName = tableName; this.ignoreAuthzErrors = ignoreAuthzErrors; this.statsParams = statsParams; }
@Test public void testGetDatasetCatalogEntityById() throws Exception { DatasetConfig datasetConfig = new DatasetConfig(); datasetConfig.setId(new EntityId("dataset-id")); datasetConfig.setFullPathList(Collections.singletonList("path")); datasetConfig.setType(VIRTUAL_DATASET); VirtualDataset virtualDataset = new VirtualDataset(); virtualDataset.setSql(""); datasetConfig.setVirtualDataset(virtualDataset); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.DATASET); namespaceContainer.setDataset(datasetConfig); when(namespaceService.getEntityById(datasetConfig.getId().getId())).thenReturn(namespaceContainer); ReflectionSettings reflectionSettings = mock(ReflectionSettings.class); when(reflectionSettings.getStoredReflectionSettings(any(NamespaceKey.class))).thenReturn(Optional.<AccelerationSettings>absent()); when(reflectionServiceHelper.getReflectionSettings()).thenReturn(reflectionSettings); DremioTable dremioTable = mock(DremioTable.class); when(dremioTable.getDatasetConfig()).thenReturn(datasetConfig); when(catalog.getTable(any(String.class))).thenReturn(dremioTable); Optional<CatalogEntity> entity = catalogServiceHelper.getCatalogEntityById(datasetConfig.getId().getId()); assertTrue(entity.isPresent()); CatalogEntity catalogEntity = entity.get(); assertTrue(catalogEntity instanceof Dataset); Dataset dataset = (Dataset) catalogEntity; assertEquals(dataset.getId(), datasetConfig.getId().getId()); }
datasetConfig.setId(new EntityId().setId(UUID.randomUUID().toString())); datasetConfig.setName("testDatasetSplitsInsert"); datasetConfig.setFullPathList(Lists.newArrayList("test", "testDatasetSplitsInsert")); SearchQuery searchQuery = SearchQueryUtils.newTermQuery(DatasetSplitIndexKeys.DATASET_ID, datasetConfig.getId().getId()); int count = ns.getSplitCount(new IndexedStore.FindByCondition().setCondition(searchQuery)); int deleted = ns.deleteSplitOrphans(DatasetSplitId.SplitOrphansRetentionPolicy.KEEP_CURRENT_VERSION_ONLY);
public void writeTo(Output output, HomeConfig message) throws IOException { if(message.id != null) output.writeObject(1, message.id, com.dremio.service.namespace.proto.EntityId.getSchema(), false); if(message.owner != null) output.writeString(2, message.owner, false); if(message.ctime != null) output.writeInt64(3, message.ctime, false); if(message.extendedConfig != null) output.writeObject(4, message.extendedConfig, ExtendedConfig.getSchema(), false); if(message.version != null) output.writeInt64(5, message.version, false); if(message.tag != null) output.writeString(6, message.tag, false); }
@Test public void testGetSpaceCatalogEntityById() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setId(new EntityId("space-id")); spaceConfig.setName("mySpace"); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); namespaceContainer.setSpace(spaceConfig); when(namespaceService.getEntityById(spaceConfig.getId().getId())).thenReturn(namespaceContainer); when(namespaceService.getEntities(Collections.singletonList(new NamespaceKey(spaceConfig.getName())))).thenReturn(Collections.singletonList(namespaceContainer)); // for children listing, we just send the space back to keep it simple when(namespaceService.list(new NamespaceKey(spaceConfig.getName()))).thenReturn(Collections.singletonList(namespaceContainer)); Optional<CatalogEntity> catalogEntityById = catalogServiceHelper.getCatalogEntityById(spaceConfig.getId().getId()); assertTrue(catalogEntityById.isPresent()); CatalogEntity catalogEntity = catalogEntityById.get(); assertTrue(catalogEntity instanceof Space); Space space = (Space) catalogEntity; assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getChildren().size(), 1); }
return; case 1: message.id = input.mergeObject(message.id, com.dremio.service.namespace.proto.EntityId.getSchema())
@VisibleForTesting static DatasetSplitId ofUnsafe(EntityId datasetId, long splitVersion, String splitKey) { final String datasetIdAsString = datasetId.getId(); String compoundSplitId = SPLIT_ID_JOINER.join(datasetIdAsString, splitVersion, splitKey); return new DatasetSplitId(compoundSplitId, datasetIdAsString, splitVersion, splitKey); } private DatasetSplitId(String compoundSplitId, String datasetId, long splitVersion, String splitKey) {
@Override public EntityId revert(byte[] v) { return new EntityId(StringSerializer.INSTANCE.revert(v)); }
void shallowSave(SourceTableDefinition accessor) throws NamespaceException{ NamespaceKey key = accessor.getName(); DatasetConfig shallow = new DatasetConfig(); shallow.setId(new EntityId().setId(UUID.randomUUID().toString())); shallow.setCreatedAt(System.currentTimeMillis()); shallow.setName(key.getName()); shallow.setFullPathList(key.getPathComponents()); shallow.setType(accessor.getType()); shallow.setSchemaVersion(DatasetHelper.CURRENT_VERSION); systemUserNamespaceService.addOrUpdateDataset(key, shallow); }
HomeConfig homeConfig = new HomeConfig(); homeConfig.setOwner("user"); homeConfig.setId(new EntityId("home-id")); when(namespaceService.getHome(new HomePath(HomeName.getUserHomePath("user")).toNamespaceKey())).thenReturn(homeConfig); spaceConfig.setId(new EntityId("space-id")); when(namespaceService.getSpaces()).thenReturn(Arrays.asList(spaceConfig)); sourceConfig.setId(new EntityId("source-id")); when(sourceService.getSources()).thenReturn(Arrays.asList(sourceConfig)); if (item.getContainerType() == CatalogItem.ContainerSubType.HOME) { homeCount++; assertEquals(item.getId(), homeConfig.getId().getId()); assertEquals(item.getId(), spaceConfig.getId().getId()); assertEquals(item.getId(), sourceConfig.getId().getId());
public void writeTo(Output output, FolderConfig message) throws IOException { if(message.id != null) output.writeObject(1, message.id, com.dremio.service.namespace.proto.EntityId.getSchema(), false); if(message.fullPath != null) { for(String fullPath : message.fullPath) { if(fullPath != null) output.writeString(2, fullPath, true); } } if(message.name != null) output.writeString(3, message.name, false); if(message.isPhysicalDataset != null) output.writeBool(4, message.isPhysicalDataset, false); if(message.extendedConfig != null) output.writeObject(5, message.extendedConfig, ExtendedConfig.getSchema(), false); if(message.version != null) output.writeInt64(6, message.version, false); if(message.tag != null) output.writeString(7, message.tag, false); }
@Override public byte[] convert(EntityId v) { return StringSerializer.INSTANCE.convert(v.getId()); }
@Override public EntityId fromJson(String v) throws IOException { return new EntityId(StringSerializer.INSTANCE.fromJson(v)); }
private void addHome(String name) throws Exception { final HomeConfig home = new HomeConfig() .setId(new EntityId().setId(UUID.randomUUID().toString())) .setOwner(name); final NameSpaceContainer container = new NameSpaceContainer() .setType(NameSpaceContainer.Type.HOME) .setFullPathList(Arrays.asList(name)) .setHome(home); namespaceStore.put(NamespaceServiceImpl.getKey(new NamespaceKey("@" + name)), container); }
public void writeTo(Output output, SpaceConfig message) throws IOException { if(message.id != null) output.writeObject(1, message.id, com.dremio.service.namespace.proto.EntityId.getSchema(), false); if(message.name != null) output.writeString(2, message.name, false); if(message.description != null) output.writeString(3, message.description, false); if(message.pinned != null) output.writeBool(4, message.pinned, false); if(message.readonly != null) output.writeBool(5, message.readonly, false); if(message.ctime != null) output.writeInt64(6, message.ctime, false); if(message.extendedConfig != null) output.writeObject(7, message.extendedConfig, ExtendedConfig.getSchema(), false); if(message.version != null) output.writeInt64(8, message.version, false); if(message.tag != null) output.writeString(9, message.tag, false); }
@Override public String toJson(EntityId v) throws IOException { return StringSerializer.INSTANCE.toJson(v.getId()); }
/** helper method that sets the given id in given container */ static void setId(NameSpaceContainer container, String id) { switch (container.getType()) { case SOURCE: container.getSource().setId(new EntityId(id)); return; case SPACE: container.getSpace().setId(new EntityId(id)); return; case HOME: container.getHome().setId(new EntityId(id)); return; case FOLDER: container.getFolder().setId(new EntityId(id)); return; case DATASET: container.getDataset().setId(new EntityId(id)); return; default: throw new RuntimeException("Invalid container type"); } }
private DatasetConfig saveDataset(List<String> path, DatasetType type, Function<DatasetConfig, DatasetConfig> transformer) throws NamespaceException { final NamespaceKey key = new NamespaceKey(path); final byte[] binaryKey = NamespaceServiceImpl.getKey(key); final Optional<DatasetConfig> oldDataset = Optional.ofNullable(namespaceStore.get(binaryKey)).map(NameSpaceContainer::getDataset); final DatasetConfig datasetConfig = transformer.apply(new DatasetConfig() .setId(oldDataset.map(DatasetConfig::getId).orElse(new EntityId().setId(UUID.randomUUID().toString()))) .setName(path.get(path.size() - 1)) .setFullPathList(path) .setType(type) .setTag(oldDataset.map(DatasetConfig::getTag).orElse(null)) .setOwner("dremio")); final NameSpaceContainer container = new NameSpaceContainer() .setType(NameSpaceContainer.Type.DATASET) .setFullPathList(path) .setDataset(datasetConfig); namespaceStore.put(binaryKey, container); return datasetConfig; }