@Override public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) { log.debug("Start: Create table {}", tableInfo.getName()); Preconditions.checkArgument(tableInfo.getSerde() == null || !Strings.isNullOrEmpty(tableInfo.getSerde().getOwner()), "Table owner is null or empty"); final QualifiedName tableName = tableInfo.getName(); if (tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName()) != null) { throw new TableAlreadyExistsException(tableName); } final Database database = databaseDao .getBySourceDatabaseName(catalogName, tableName.getDatabaseName()); if (database == null) { throw new DatabaseNotFoundException(QualifiedName.ofDatabase(catalogName, tableName.getDatabaseName())); } tableDao.save(infoConverter.fromTableInfo(database, tableInfo)); log.debug("End: Create table {}", tableInfo.getName()); }
/** * Converts from storage info to s3 location. * @param storageInfo storage info * @return location */ Location fromStorageInfo(final StorageInfo storageInfo) { final Location result = new Location(); if (storageInfo != null) { result.setUri(storageInfo.getUri()); final Info info = new Info(); info.setLocation(result); info.setOwner(storageInfo.getOwner()); info.setInputFormat(storageInfo.getInputFormat()); info.setOutputFormat(storageInfo.getOutputFormat()); info.setSerializationLib(storageInfo.getSerializationLib()); final Map<String, String> parameters = Maps.newHashMap(); if (storageInfo.getParameters() != null) { parameters.putAll(storageInfo.getParameters()); } if (storageInfo.getSerdeInfoParameters() != null) { parameters.putAll(storageInfo.getSerdeInfoParameters()); } info.setParameters(parameters); result.setInfo(info); } return result; }
/** * Converts to PartitionDto. * * @param partition connector partition * @return Metacat partition Info */ @Override public PartitionInfo toPartitionInfo( final TableInfo tableInfo, final Partition partition ) { final QualifiedName tableName = tableInfo.getName(); final QualifiedName partitionName = QualifiedName.ofPartition(tableName.getCatalogName(), tableName.getDatabaseName(), tableName.getTableName(), getNameFromPartVals(tableInfo, partition.getValues())); final String owner = notNull(tableInfo.getSerde()) ? tableInfo.getSerde().getOwner() : ""; final AuditInfo auditInfo = AuditInfo.builder() .createdDate(epochSecondsToDate(partition.getCreateTime())) .lastModifiedDate(epochSecondsToDate(partition.getLastAccessTime())).build(); return PartitionInfo.builder() .serde(toStorageInfo(partition.getSd(), owner)) .name(partitionName) .auditInfo(auditInfo) .metadata(partition.getParameters()) .build(); }
/** * Converts to PartitionDto. * * @param partition connector partition * @return Metacat partition Info */ @Override public PartitionInfo toPartitionInfo( final TableInfo tableInfo, final Partition partition ) { final QualifiedName tableName = tableInfo.getName(); final QualifiedName partitionName = QualifiedName.ofPartition(tableName.getCatalogName(), tableName.getDatabaseName(), tableName.getTableName(), getNameFromPartVals(tableInfo, partition.getValues())); final String owner = notNull(tableInfo.getSerde()) ? tableInfo.getSerde().getOwner() : ""; final AuditInfo auditInfo = AuditInfo.builder() .createdDate(epochSecondsToDate(partition.getCreateTime())) .lastModifiedDate(epochSecondsToDate(partition.getLastAccessTime())).build(); return PartitionInfo.builder() .serde(toStorageInfo(partition.getSd(), owner)) .name(partitionName) .auditInfo(auditInfo) .metadata(partition.getParameters()) .build(); }