You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/09/01 17:00:13 UTC

[GitHub] [accumulo] keith-turner commented on a diff in pull request #2910: Add ability to retrieve TimeType for a table

keith-turner commented on code in PR #2910:
URL: https://github.com/apache/accumulo/pull/2910#discussion_r960898970


##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java:
##########
@@ -2011,6 +2015,34 @@ public ImportDestinationArguments importDirectory(String directory) {
     return new BulkImport(directory, context);
   }
 
+  @Override
+  public TimeType getTimeType(final String tableName) throws TableNotFoundException {
+    if (tableName.equals(RootTable.NAME)) {
+      throw new IllegalArgumentException("accumulo.root table has no TimeType");
+    }
+    String systemTableToCheck =
+        MetadataTable.NAME.equals(tableName) ? RootTable.NAME : MetadataTable.NAME;
+    final Scanner scanner = context.createScanner(systemTableToCheck, Authorizations.EMPTY);
+    String tableId = tableIdMap().get(tableName);
+    if (tableId == null) {
+      throw new TableNotFoundException(null, tableName, "specified table does not exist");
+    }
+    final Text start = new Text(tableId);
+    final Text end = new Text(start);
+    start.append(new byte[] {'<'}, 0, 1);
+    end.append(new byte[] {'<'}, 0, 1);
+    scanner.setRange(new Range(start, end));
+    MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN.fetch(scanner);
+    Entry<Key,Value> next = scanner.iterator().next();
+    Value val = next.getValue();
+    if (val.toString().startsWith("L")) {
+      return TimeType.LOGICAL;
+    } else if (val.toString().startsWith("M")) {
+      return TimeType.MILLIS;
+    }
+    throw new RuntimeException("Failed to retrieve TimeType");

Review Comment:
   May be able to use ample for this.  Also may not need a special case for root tablet w/ ample, seems like it will return the time type logical.  But not sure, this is the [code that initializes the root tablet metadata](https://github.com/apache/accumulo/blob/114704bb58a37073a0401c3b6f479761089bd1fb/server/base/src/main/java/org/apache/accumulo/server/init/ZooKeeperInitializer.java#L189-L206) and makes me think it would return logical.
   
   ```suggestion
        String tableId = tableIdMap().get(tableName);
       if (tableId == null) {
         throw new TableNotFoundException(null, tableName, "specified table does not exist");
       }
           Optional<TabletMetadata> tabletMetadata = context.getAmple().readTablets().forTable(tableId)
               .fetch(ColumnType.TIME).checkConsistency().build().stream().findFirst();
       if(tabletMetadata.isPresent()) {
         return tabletMetadata.get().getTime().getType();
       } else {
         throw new RuntimeException("Failed to retrieve TimeType"))
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org