@Override public void addProperties(Map<String, String> props) { super.addProperties(props); props.put(MetastoreUtil.getDimTypePropertyKey(getName()), type); if (numOfDistinctValues.isPresent()) { props.put(MetastoreUtil.getDimNumOfDistinctValuesPropertyKey(getName()), String.valueOf(numOfDistinctValues.get())); } if (values.isPresent() && !this.values.get().isEmpty()) { props.put(MetastoreUtil.getInlineDimensionValuesKey(getName()), MetastoreUtil.getStr(values.get())); } }
@Override public boolean equals(Object obj) { if (!super.equals(obj)) { return false; } BaseDimAttribute other = (BaseDimAttribute) obj; if (this.getType() == null) { if (other.getType() != null) { return false; } } else if (!this.getType().equalsIgnoreCase(other.getType())) { return false; } else if (!this.numOfDistinctValues.equals(other.numOfDistinctValues)) { return false; } else if (!this.getValues().equals(other.getValues())) { return false; } return true; } }
@Override public void addProperties(Map<String, String> props) { super.addProperties(props); StringBuilder chainNamesValue = new StringBuilder(); StringBuilder refColsValue = new StringBuilder(); Iterator<ChainRefCol> iterator = chainRefColumns.iterator(); // Add the first without appending separator ChainRefCol chainRefCol = iterator.next(); chainNamesValue.append(chainRefCol.getChainName()); refColsValue.append(chainRefCol.getRefColumn()); while (iterator.hasNext()) { chainRefCol = iterator.next(); chainNamesValue.append(CHAIN_REF_COL_SEPARATOR).append(chainRefCol.getChainName()); refColsValue.append(CHAIN_REF_COL_SEPARATOR).append(chainRefCol.getRefColumn()); } props.put(MetastoreUtil.getDimRefChainNameKey(getName()), chainNamesValue.toString()); props.put(MetastoreUtil.getDimRefChainColumnKey(getName()), refColsValue.toString()); }
/** * This is used only for serializing * * @param name * @param props */ public BaseDimAttribute(String name, Map<String, String> props) { super(name, props); this.type = getDimType(name, props); this.numOfDistinctValues = getDimNumOfDistinctValues(name, props); this.values = getValues(name, props); }
assertNotNull(dim.getAttributeByName("col3")); BaseDimAttribute col3 = (BaseDimAttribute) dim.getAttributeByName("col3"); assertEquals(col3.getDescription(), "inline column"); assertEquals(col3.getDisplayString(), "Column3"); assertEquals(col3.getType(), "string"); assertEquals(col3.getValues().get().get(0), "Val1"); assertEquals(col3.getValues().get().get(1), "Val2"); assertEquals(col3.getValues().get().get(2), "Val3"); assertEquals(col3.getNumOfDistinctValues().get(), (Long) 3L); assertNotNull(dim.getAttributeByName("col4")); HierarchicalDimAttribute col4 = (HierarchicalDimAttribute) dim.getAttributeByName("col4"); assertEquals(col4.getDescription(), "hierarchical column"); BaseDimAttribute col4h1 = (BaseDimAttribute) col4.getHierarchy().get(0); assertEquals(col4h1.getName(), "col4-h1"); assertEquals(col4h1.getType(), "string"); assertEquals(col4h1.getDescription(), "inline column"); assertEquals(col4h1.getDisplayString(), "Column4-h1"); assertEquals(col4h1.getValues().get().get(0), "Val1-h1"); assertEquals(col4h1.getValues().get().get(1), "Val2-h1"); assertEquals(col4h1.getValues().get().get(2), "Val3-h1"); assertEquals(col4h1.getNumOfDistinctValues().get(), (Long) 3L); BaseDimAttribute col4h2 = (BaseDimAttribute) col4.getHierarchy().get(1); assertEquals(col4h2.getName(), "col4-h2"); assertEquals(col4h2.getType(), "string"); assertEquals(col4h2.getDescription(), "base column"); assertEquals(col4h2.getDisplayString(), "Column4-h2"); ReferencedDimAttribute col4h3 = (ReferencedDimAttribute) col4.getHierarchy().get(2); assertEquals(col4h3.getName(), "col4-h3");
xd.setType(bd.getType()); Optional<Long> numOfDistinctValues = bd.getNumOfDistinctValues(); if (numOfDistinctValues.isPresent()) { xd.setNumDistinctValues(numOfDistinctValues.get()); if (bd.getValues().isPresent()) { xd.getValues().addAll(bd.getValues().get());
new BaseDimAttribute(new FieldSchema(col.getName(), "string", "invalid col"), col.getDisplayString(), oneWeekBack, null, col.getCost(), null); cube.alterDimension(newDim2); client.alterCube(TEST_CUBE_NAME, cube);
toAlter.alterAttribute(new BaseDimAttribute(new FieldSchema("newZipDim", "int", "new dim added"), null, null, null, null, 1000L)); toAlter.alterAttribute(new ReferencedDimAttribute(new FieldSchema("newRefDim", "int", "new ref-dim added"), "New city ref", "cubecity", "name", null, null, null)); toAlter.alterAttribute(new BaseDimAttribute(new FieldSchema("f2", "varchar", "modified field"))); toAlter.alterAttribute(new BaseDimAttribute(new FieldSchema("stateid", "int", "state id"), "State refer altered", null, null, null)); toAlter.removeAttribute("f1"); assertEquals(((BaseDimAttribute) newzipdim).getType(), "int"); assertEquals((((BaseDimAttribute) newzipdim).getNumOfDistinctValues().get()), Long.valueOf(1000)); assertEquals(((BaseDimAttribute) f2).getType(), "varchar");
"Measure3Altered", null, "MAX", "alterunit")); toAlter.removeMeasure("msr4"); toAlter.alterDimension(new BaseDimAttribute(new FieldSchema("testAddDim1", "string", "dim to add"))); toAlter.alterDimension(new BaseDimAttribute(new FieldSchema("dim1", "int", "basedim altered"))); toAlter.removeDimension("location2"); toAlter.addTimedDimension("zt"); assertNotNull(altered.getDimAttributeByName("testAddDim1")); BaseDimAttribute addedDim = (BaseDimAttribute) altered.getDimAttributeByName("testAddDim1"); assertEquals(addedDim.getType(), "string"); assertEquals(addedDim.getDescription(), "dim to add"); assertTrue(altered.getTimedDimensions().contains("zt")); assertEquals(altered.getMeasureByName("msr3").getDisplayString(), "Measure3Altered");
assertEquals(hcube.getDimAttributeByName("dim1").getDescription(), "first dimension"); assertEquals(hcube.getDimAttributeByName("dim1").getDisplayString(), "Dimension1"); assertEquals((((BaseDimAttribute) hcube.getDimAttributeByName("dim1")).getNumOfDistinctValues().get()), Long.valueOf(2000)); assertEquals(hcube.getDimAttributeByName("testdim2col2").getDisplayString(), "Chained Dimension"); assertEquals(hcube.getDimAttributeByName("testdim2col2").getDescription(), "ref chained dimension"); assertEquals(((BaseDimAttribute) hcube.getDimAttributeByName("dim4")).getType(), "struct<a:int,b:array<string>,c:map<int,array<struct<x:int,y:array<int>>>"); ReferencedDimAttribute testdim2col2 = (ReferencedDimAttribute) hcube.getDimAttributeByName("testdim2col2"); assertEquals((testdim2col2.getNumOfDistinctValues().get()), Long.valueOf(1000)); assertEquals(((BaseDimAttribute) hcube.getDimAttributeByName("dim2")).getNumOfDistinctValues().isPresent(), false);
@Test(priority = 2) public void testAlterDerivedCube() throws Exception { String name = "alter_derived_cube"; client.createDerivedCube(CUBE_NAME, name, measures, dimensions, emptyHashMap, 0L); // Test alter cube Table cubeTbl = client.getHiveTable(name); DerivedCube toAlter = new DerivedCube(cubeTbl, (Cube) client.getCube(CUBE_NAME)); toAlter.addMeasure("msr4"); toAlter.removeMeasure("msr3"); toAlter.addDimension("dim1StartTime"); toAlter.removeDimension("dim1"); assertNotNull(toAlter.getMeasureByName("msr4")); assertNotNull(toAlter.getMeasureByName("msr2")); assertNull(toAlter.getMeasureByName("msr3")); assertNotNull(toAlter.getDimAttributeByName("dim1StartTime")); assertNotNull(toAlter.getDimAttributeByName("dim2")); assertNull(toAlter.getDimAttributeByName("dim1")); client.alterCube(name, toAlter); DerivedCube altered = (DerivedCube) client.getCube(name); assertEquals(toAlter, altered); assertNotNull(altered.getMeasureByName("msr4")); CubeMeasure addedMsr = altered.getMeasureByName("msr4"); assertEquals(addedMsr.getType(), "bigint"); assertNotNull(altered.getDimAttributeByName("dim1StartTime")); BaseDimAttribute addedDim = (BaseDimAttribute) altered.getDimAttributeByName("dim1StartTime"); assertEquals(addedDim.getType(), "string"); assertNotNull(addedDim.getStartTime()); client.dropCube(name); assertFalse(client.tableExists(name)); }
@Test public void testNamedStrings() { Set<CubeDimAttribute> attrs = new LinkedHashSet<CubeDimAttribute>(); attrs.add(new BaseDimAttribute(new FieldSchema("first", "string", ""))); attrs.add(new BaseDimAttribute(new FieldSchema("second", "string", ""))); attrs.add(new BaseDimAttribute(new FieldSchema("biggggger", "string", ""))); List<String> names = MetastoreUtil.getNamedStrs(attrs, 10); Assert.assertEquals(names.size(), 3); Assert.assertEquals(names.get(0), "first,"); Assert.assertEquals(names.get(1), "second,"); Assert.assertEquals(names.get(2), "biggggger"); Map<String, String> props = new HashMap<String, String>(); MetastoreUtil.addNameStrings(props, "test.key", attrs); String propValue = MetastoreUtil.getNamedStringValue(props, "test.key"); Assert.assertEquals(props.size(), 2); Assert.assertEquals(props.get("test.key.size"), "1"); Assert.assertEquals(propValue, "first,second,biggggger"); props = new HashMap<String, String>(); MetastoreUtil.addNameStrings(props, "test.key", attrs, 10); propValue = MetastoreUtil.getNamedStringValue(props, "test.key"); Assert.assertEquals(props.size(), 4); Assert.assertEquals(props.get("test.key.size"), "3"); Assert.assertEquals(propValue, "first,second,biggggger"); } }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((getType() == null) ? 0 : getType().toLowerCase().hashCode()); if (numOfDistinctValues.isPresent()) { result = prime * result + numOfDistinctValues.get().hashCode(); } if (values.isPresent()) { result = prime * result + values.get().hashCode(); } return result; }
xd.setType(bd.getType()); Optional<Long> numOfDistinctValues = bd.getNumOfDistinctValues(); if (numOfDistinctValues.isPresent()) { xd.setNumDistinctValues(numOfDistinctValues.get()); if (bd.getValues().isPresent()) { xd.getValues().addAll(bd.getValues().get());
/** * This is used only for serializing * * @param name * @param props */ public BaseDimAttribute(String name, Map<String, String> props) { super(name, props); this.type = getDimType(name, props); this.numOfDistinctValues = getDimNumOfDistinctValues(name, props); this.values = getValues(name, props); }
cubeDimensions.add(new BaseDimAttribute(new FieldSchema("dim1", "id", "ref dim"), "dim with tag", null, null, null, null, null, tag1));
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((getType() == null) ? 0 : getType().toLowerCase().hashCode()); if (numOfDistinctValues.isPresent()) { result = prime * result + numOfDistinctValues.get().hashCode(); } if (values.isPresent()) { result = prime * result + values.get().hashCode(); } return result; }
@Override public boolean equals(Object obj) { if (!super.equals(obj)) { return false; } BaseDimAttribute other = (BaseDimAttribute) obj; if (this.getType() == null) { if (other.getType() != null) { return false; } } else if (!this.getType().equalsIgnoreCase(other.getType())) { return false; } else if (!this.numOfDistinctValues.equals(other.numOfDistinctValues)) { return false; } else if (!this.getValues().equals(other.getValues())) { return false; } return true; } }
zipAttrs.add(new BaseDimAttribute(new FieldSchema("zipcode", "int", "code"))); zipAttrs.add(new BaseDimAttribute(new FieldSchema("f1", "string", "field1"))); zipAttrs.add(new BaseDimAttribute(new FieldSchema("f2", "string", "field1"))); zipAttrs.add(new BaseDimAttribute(new FieldSchema("stateid", "int", "state id"), "State refer", null, null, null)); zipAttrs.add(new BaseDimAttribute(new FieldSchema("cityid", "int", "city id"), "City refer", null, null, null)); zipAttrs.add(new BaseDimAttribute(new FieldSchema("countryid", "int", "country id"), "Country refer", null, null, null)); zipAttrs.add(new ReferencedDimAttribute(new FieldSchema("statename", "name", "state name"), "State Name", cityAttrs.add(new BaseDimAttribute(new FieldSchema("id", "int", "code"))); cityAttrs.add(new BaseDimAttribute(new FieldSchema("name", "string", "city name"))); cityAttrs.add(new BaseDimAttribute(new FieldSchema("stateid", "int", "state id"), "State refer", null, null, null)); cityAttrs.add(new ReferencedDimAttribute(new FieldSchema("statename", "name", "state name"), "State Name", "citystate", "name", null, null, null)); stateAttrs.add(new BaseDimAttribute(new FieldSchema("id", "int", "state id"), "State ID", null, null, null)); stateAttrs.add(new BaseDimAttribute(new FieldSchema("name", "string", "state name"))); stateAttrs.add(new BaseDimAttribute(new FieldSchema("capital", "string", "state capital"))); stateAttrs.add(new BaseDimAttribute(new FieldSchema("countryid", "int", "country id"), "Country refer", null, null, null)); stateAttrs.add(new ReferencedDimAttribute(new FieldSchema("countryname", "name", "country name"), "country Name", countryAttrs.add(new BaseDimAttribute(new FieldSchema("id", "int", "country id"))); countryAttrs.add(new BaseDimAttribute(new FieldSchema("name", "string", "country name"))); countryAttrs.add(new BaseDimAttribute(new FieldSchema("capital", "string", "country capital"))); countryAttrs.add(new BaseDimAttribute(new FieldSchema("region", "string", "region name"))); countryDim = new Dimension("countrydim", countryAttrs);
@Override public void addProperties(Map<String, String> props) { super.addProperties(props); props.put(MetastoreUtil.getDimTypePropertyKey(getName()), type); if (numOfDistinctValues.isPresent()) { props.put(MetastoreUtil.getDimNumOfDistinctValuesPropertyKey(getName()), String.valueOf(numOfDistinctValues.get())); } if (values.isPresent() && !this.values.get().isEmpty()) { props.put(MetastoreUtil.getInlineDimensionValuesKey(getName()), MetastoreUtil.getStr(values.get())); } }